• 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

0xbeef to integer

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how does one see that "0xbeef" in

char c3 = 0xbeef;

has integer value of 48879 ?

Thx.
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The hex value of 0xbeef can be converted to decimal as follows:

f -> 15 * (16 to power of 0) = 15 * 1 = 15
e -> 14 * (16 to power of 1) = 14 * 16 = 224
e -> 14 * (16 to power of 2) = 14 * 256 = 3584
b -> 11 * (16 to power of 3) = 11 * 4096 = 45056

Added together, you get 48879.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly.

You should recognize that a numeric literal that begins with 0 is octal (base 8), and one that begins with 0x is hexadecimal (base 16). In hexadecimal, the letters a, b, c, d, e, and f are used to represent base-10 values 10, 11, 12, 13, 14, and 15 respectively.

(Note: The "x" can be either upper or lowercase -- just like an "L" to denote long, an "s" to denote short, or an "e" to denote exponent.)
 
Netty poestel
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Chris , Marc.
final query on this topic, do these kind of 'otherwise calculator-calculations' [ powers of 16 multiplied and added with 2 digit numbers ] a regular feature in the exams ?

Thx. all
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic