dec2base
Converts a nonnegative integer to text in a given base (2 to 36).
Category: Language Fundamentals > Data Types
Syntax
s = dec2base(d, base)
Digits of d in base.
s = dec2base(d, base, len)
Pads with leading zeros to at least len digits.
Description
The digits are 0-9 followed by uppercase A-Z. The value is repeatedly divided by the base and the remainders form the digits, last remainder first. dec2bin and dec2hex are the same operation for base 2 and 16. The reverse is base2dec.
Input arguments
d- Nonnegative integers (up to
flintmax). base- Integer from 2 to 36.
len- Minimum number of digits.
Output arguments
s- Char array, one row per element of
d, left padded with zeros to the same length.
Example
Several bases
dec2base(10, 3)
dec2base(255, 16)
dec2base(10, 2, 8)
Output
ans = '101'
ans = 'FF'
ans = '00001010'
Notes
Only a numeric base is accepted; a string of custom symbols as the base is not supported.