Java Reference
In-Depth Information
In addition, the
Integer
and
Long
classes each have the following meth-
ods, where
type
is either
int
or
long
, respectively:
public static String
toString(
type
val, int radix)
Returns a string representation of the given value in the given
radix. If radix is out of range then a radix of 10 is used.
public static String
toBinaryString(
type
val)
Returns a string representation of the two's complement bit
pattern of the given value. For positive values this is the
same as
toString(value,2)
. For negative values the sign of
the value is encoded in the bit pattern, not as a leading
minus character. For example,
Integer.toBinaryString(-10)
re-
turns
"11111111111111111111111111110110"
. These string repres-
entations for negative values cannot be used with correspond-
ing
parse
Type
methods because the magnitude represented by
the string will always be greater than
MAX_VALUE
for the given
type.
public static String
toOctalString(
type
val)
Returns a string representation of the given value in an un-
signed base 8 format. For example,
Integer.toOctalString(10)
returns
"12"
. Negative values are treated as described in
toBinaryString
. For example,
Integer.toOctalString(-10)
re-
turns
"37777777766"
.
public static String
toHexString(
type
val)
Returns a string representation of the given value in an un-
signed base 16 format. For example,
Integer.toHexString(10)
returns
"a"
. Negative values are treated as described in
toBin-
aryString
.
For
example,
Integer.toHexString(-10)
returns
"fffffff6"
.