• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how 0x7f =127

 
Ranch Hand
Posts: 1283
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
7*16 + 15 = 127
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See: Hexadecimal
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic