Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!

# how 0x7f =127

Kaustubh G Sharma
Ranch Hand
Posts: 1283
I am not able to understand conversion for 0x7f to 127. I do understand hexadecimal system.. but for this conversion I am confused please help

Keith Lynn
Ranch Hand
Posts: 2409
7*16 + 15 = 127

Kaustubh G Sharma
Ranch Hand
Posts: 1283
ohk but 16 represent which char? and there's no addition sign between them... what is the logic behind it?

Keith Lynn
Ranch Hand
Posts: 2409
16 is the base of the hexadecimal system.

Think of how you would convert 11011 from binary to decimal.

1*2^4 + 1*2^3 + 0*2^2 + 1*2^1 + 1*2^0 = 16 + 8 + 0 + 2 + 1 = 27

Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15284
39

Steve Luke
Bartender
Posts: 4181
21
Kaustubh G Sharma wrote:ohk but 16 represent which char? and there's no addition sign between them... what is the logic behind it?

How does 23 (in decimal) = 23? Because it is (2 * 10) + 3.

The first digit is 2, which is in the 10s position. So to get the value of the first digit you do (2 * 10). The second digit is in the ones position, and has a value of 3. To get the total value of the number you sum the values of the digits, so 23 == (2 * 10) + 3.

Since you understand Hexadecimal you should be able to apply the same conversion to 0x7f.

Winston Gutkowski
Bartender
Posts: 10417
63
Kaustubh G Sharma wrote:I am not able to understand conversion for 0x7f to 127. I do understand hexadecimal system.. but for this conversion I am confused please help

I fear that several people (including me) are having a problem understanding your problem. If you "do understand hexadecimal system", then surely you understand that '7f' can't be anything but 127 decimal?

Or is it the '0x' bit that is bothering you? That is simply a prefix that tells the Java compiler that the characters that follow are hexadecimal.

Winston

Kaustubh G Sharma
Ranch Hand
Posts: 1283
Winston Gutkowski wrote:
Kaustubh G Sharma wrote:I am not able to understand conversion for 0x7f to 127. I do understand hexadecimal system.. but for this conversion I am confused please help

I fear that several people (including me) are having a problem understanding your problem. If you "do understand hexadecimal system", then surely you understand that '7f' can't be anything but 127 decimal?

Or is it the '0x' bit that is bothering you? That is simply a prefix that tells the Java compiler that the characters that follow are hexadecimal.

Winston

Yes Winston I was confused because of this 0x thing.. Now my doubt is clear.. Thanks to all of you