The answer to the question answered integers printed in decimal format , but I'm looking for an elegant way to do the same with non-decimal integers (like binary, octal, hexadecimal).
Creating lines like this is easy:
String intAsString = Integer.toString(12345, 8);
will create a String with the octal representation of the integer value 12345. But how to format it so that the string has 10 digits, in addition to calculating the number of zeros and assembling a new line "manually".
A typical use case would be to create binary numbers with a fixed number of bits (for example, 16, 32, ...), in which we would like to have all the digits, including leading zeros.
java
Andreas_D Jun 30 '10 at 13:30 2010-06-30 13:30
source share