programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Binar representation of octal & hexadecimal nos

Veena Pointi
Ranch Hand
Posts: 442
How to convert hexadecimal & octal numbers to binary?Should I convert them first to decimal & then to binary?Can someone explain with example?
Thanks
Veena

Dan Chisholm
Ranch Hand
Posts: 1865
Veena,
You certainly should not convert to decimal before converting to binary. The only reason for the popularity of octal and hex is the fact that both are very easy to convert to binary.
Each hex character represents four bits. To convert hex to binary, just write down the four bits that represent each hex character.
0x1234 = 0001 0010 0011 0100
What could be easier than that?
Three octal characters are needed to represent a single 8-bit byte. The two characters on the right each represent three bits so both of the rightmost characters represent the six least significant bits of the byte. The third character from the right represents the two most significant bits. Java uses a leading zero as a prefix that indicates that the number is octal.
0123 = 01 010 011
0311 = 11 001 001
011 = 00 001 001
01 = 00 000 001
Octal was very popular when most computers were eight bit machines. Hexadecimal is a better representation when the data values are composed of more than one byte.

Barry Gaunt
Ranch Hand
Posts: 7729
This may help (Acrobat PDF!)
-Barry
[ August 09, 2002: Message edited by: Barry Gaunt ]

Veena Pointi
Ranch Hand
Posts: 442
It is a lot easier than converting decimal numbers to binary!.Thanks Dan.
Veena