Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Couple quick questions about octel and hex notation

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great, thanks!
 
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic