Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Couple quick questions about octel and hex notation  RSS feed

 
David Miranda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Im trying to understand what the '0x' in lets say 0x0F stands for...

Does the '0x' just stand for 'this is hex'?

Also...

Lets say we have a number '010'...this is octel. Is putting a '0' in front of a number the only way to signify that a number is octel?

Thanks!

Dave
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Miranda:

Does the '0x' just stand for 'this is hex'?


Yes, that's all.


Lets say we have a number '010'...this is octel. Is putting a '0' in front of a number the only way to signify that a number is octel?


Yes.
 
David Miranda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great, thanks!
 
Ryan McGuire
Ranch Hand
Posts: 1142
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simulpost! Oh well, I'll leave this here for the joke at the end if nothing else.
-------------------
Yes, 0x or 0X means this is a hexadecimal number.
And yes, just a leading 0 is the only way to make an octal integer contstant.

0x0c == 014 == 12

The thing that trips many people up is using leading zeros to make columns line up:



formatDate(CHRISTMAS) returns "12/25"
formatDate(HALLOWEEN) returns "10/30"
but formatDate(GROUNDHOG) returns "1/30"

The final static declarations should have been...


But octal and hex are handy for defining bits. Compare...


to...



Ryan


P.S. This talk of holidays reminds me of a riddle:

Why do programmers get Halloween and Christmas mixed up?







Because 31 Oct = 25 Dec
[ April 15, 2005: Message edited by: Ryan McGuire ]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!