• 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

integral literals? 0xff

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am having difficulty understanding why the values represented in these statements are what they are
int b=0xff
int i= 0x7FFF
When I compile and run i get 255 and 2047.
Is there an easy way to understand what and how these numbers represent?
There was a great posting a little while ago explaining Octal and Hex numbers, and I am clear on their values.
I am scheduled to write the exam a week from today and would like to iron out these bugs in my brain. Thanks for your help.
p.s. Should I understand how to do these calculations. I see them occasionally on mock exams.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there you go:
Topic: converting decimals to binary
Topic: value & 0xff
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


int b=0xff
int i= 0x7FFF
When I compile and run i get 255 and 2047.


Val gave some great links, but 0x7FFF is not 2047, it's 32767.
Corey
 
Duncan Allen
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx guys,
You are quite right Corey.
typo , one too many f's
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a simple little rule.
1. ALL integral literals are of type int, regardless of their radix (base notation).
Examples:
127 //int literal
456789 //int literal
016 //int literal represented in OCTAL notation
0xFF //int literal represented in HEXADECIMAL notation
0Xffabcd //int literal represented in HEX.
Rule #2:
2. All floating point literals are of type double, casts not withstanding (ie, yes you can include an F or f or (float) and then it won't be a double but I'm just talking about a plain undecorated floating-point literal value)
examples:
1. //double
.1 //double
0.1 //double
123.456 //Can you guess what this is?
789.12 //boolean.
NO THAT WAS A JOKE. IT'S ALSO A DOUBLE.
Hope this makes it crystal clear
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic