programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Wrapper class Long.toString() method

Ranch Hand
Posts: 486
System.out.println(Long.toString(15, 16)); is printing f3.
But

author
Sheriff
Posts: 23364
127

Originally posted by Shiva Mohan:
System.out.println(Long.toString(15, 16)); is printing f3.
But

The first parameter is the long value to be converted to a string. In your case, it is a value of 15 (in decimal format). This should convert to a value of "f" in base 16 format.

In the second case, it is a value of 11110011 (also in decimal format). Which converts to a value of "a9867b" in base 16 format.

Henry

Shiva Mohan
Ranch Hand
Posts: 486
Thanks Henry for the reply.But I have a doubt.

11110011 is a decimal value.So first convert the decimal value to binary. Then convert it to hexa decimal.I got it.

Conerting 11110011 from decimal to binary value is 101010011000011001111011.The calculation part is goes on the number 5555005.
I don�t know,how to get this number? Help me.

Shiva Mohan
Ranch Hand
Posts: 486
11110011 .
/2= 5555005 rem 1
/2= 2777502 rem 1
/2= 1388751 rem 0
/2= 694375 rem 1
/2= 347187 rem 1
/2= 173593 rem 1
/2= 86796 rem 1
/2= 43398 rem 0
/2= 21699 rem 0
/2= 10849 rem 1
/2= 5424 rem 1
/2= 2712 rem 0
/2= 1356 rem 0
/2= 678 rem 0
/2= 339 rem 0
/2= 169 rem 1
/2= 84 rem 1
/2= 42 rem 0
/2= 21 rem 0
/2= 10 rem 1
/2= 5 rem 0
/2= 2 rem 1
/2= 1 rem 0
/2= 0 rem 1

Here, how did the decimal number 11110011 changed to the number 5555005.

Shiva Mohan
Ranch Hand
Posts: 486

Marshal
Posts: 57437
175
5555005 in decimal is
0101 0100 1100 0011 0011 1101 in binary or
-5------4-----c------3-----3-----d in hex
[ August 17, 2006: Message edited by: Campbell Ritchie ]

Campbell Ritchie
Marshal
Posts: 57437
175
. . . and this is 11110011 in binary:-
0000 0000 1010 1001 1000 0110 0111 1011
---0-----0-----a-----9-----8-----6-----7----b in hex.

 Bras cause cancer. And tiny ads: The WEB SERVICES and JAX-RS Course https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS