Main Content

dec2base

Convert decimal integer to its base-n representation for fi objects

Since R2021b

Description

baseStr = dec2base(D,n) returns a base-n representation of the decimal integer D. The output argument baseStr is a character array that represents digits using numeric characters, and, when n is greater than 10, letters. For example, if n is 12, the dec2base represents the numbers 9, 10, and 11 using the characters 9, A, and B, and represents the number 12 as the character sequence 10.

example

baseStr = dec2base(D,n,minDigits) returns a base-n representation of D with no fewer than minDigits digits.

Tip

dec2base returns the base-n representation of the real-world value of the values contained in fi object D.

example

Examples

collapse all

Convert a decimal number to a character vector that represents its value in base 3.

D = fi(23);
baseStr = dec2base(D,3)
baseStr =

    '212'

Convert a decimal number to a character vector that represents its value in base 12. In this base system, the characters 'A' and 'B' represent the numbers denoted as 10 and 11 in base 10.

D = fi(23);
baseStr = dec2base(D,12)
baseStr =

    '1B'

Specify the number of base-3 digits that dec2base returns. If you specify more digits than are required, then dec2base pads the output with leading zeros.

D = fi(23);
baseStr = dec2base(D,3,5)
baseStr =

    '00212'

Convert the upper bound of a signed fi object with 100-bit word length to base 36 representation.

baseStr = dec2base(upperbound(fi([],1,100,0)),36)
baseStr =

    '1PG7OTO50BLAOIQ8FPQ7'

Input Arguments

collapse all

Input array, specified as a fi array of nonnegative numbers.

D must contain finite integers. If any element of D has a fractional part, then dec2base produces an error. For example, dec2base(fi(10),8) converts fi(10) to '12', but dec2base(fi(10.5),8) produces an error.

Data Types: fi

Base of output representation, specified as an integer between 2 and 36. For example, if n is 8, then the output represents base-8 numbers.

Minimum number of digits in the output, specified as a positive integer.

  • If D can be represented with fewer than minDigits digits, then dec2base pads the output with leading zeros.

  • If D is so large that it must be represented with more than minDigits digits, then dec2base returns the output with as many digits as required.

Extended Capabilities

Version History

Introduced in R2021b

See Also

| | | | | |