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
• Devaka Cooray
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Jeanne Boyarsky
• Tim Cooke
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Tim Moores
• Mikalai Zaikin
• Carey Brown
Bartenders:

Greenhorn
Posts: 12
• Number of slices to send:
Optional 'thank-you' note:
Hi
I am having difficulty converting base 10 numbers to Hexadecimal and octal numbers. I have not been able to find out the rules for conversion. Can someone please explain how to convert to these number types?
Thanks
Ian

Bartender
Posts: 612
7
• Number of slices to send:
Optional 'thank-you' note:
Easiest way to convert from decimal to binary, then
bundle in groups of three (for octal) or groups of
four (for hex):
Such as:
decimal 42
convert to binary 101010
bundle in groups of three for octal 101 010
convert to octal 52
bundle in groups of four for hex 0010 1010
convert to hex 2a
so dec 42 = bin 101010 = 52 oct = 2a hex

Ranch Hand
Posts: 52
• Number of slices to send:
Optional 'thank-you' note:
Hi ,
I am trying to explain the methods briefly.
first you take the decimal number and convert it to it's binary representation.
1)now to convert it to the Octal number
devide the binary string in group of 3 bits from right and write
the octal equivalent for it.
for ex I have taken 19.
so the binary rep is-----
00010011(I am showing in a byte)
now from right u start grouping
00 010 011
avoid the left 2 zeros since it doesnt effect the magnitude.
so the octal equivalent is 023 (since the convention is to put a 0 before a octal literal)

2)for converting it to Hexadecimal follow the same way except yo devide the bits in a group of 4 and write the Hexadecimal equivalent for each group and then put a Ox before them to denote that it is a hexadecimal number.
so in the case of decimal 19?
0001 0011
0x13
-----------------------------------------------------------
thanks
Sathi

Ranch Hand
Posts: 625
• Number of slices to send:
Optional 'thank-you' note:
Ian,

So if you have say 0137:
In decimal this equals 7*8^0 + 3*8^1 + 1*8^2 = 95
In decimal this equals 7*16^0 + 3*16^1 + 1*16^2= 311
Keep in mind that decimal 137 = 7*10^0 + 3*10^1 +1*10^2
The other responses are fine, I just wanted to show you the easy way from octal or hexadecimal in case you're having problems with that too.

Ranch Hand
Posts: 3141
• Number of slices to send:
Optional 'thank-you' note:
Hi Ian,
I've got some notes on Binary/Octal/Decimal/Heximal arithmetic posted at http://www.janeg.ca/scjp/oper/binhex.html.
Hope they help
------------------
Jane Griscti
Sun Certified Programmer for the Javaï¿½ 2 Platform

Ian Heff
Greenhorn
Posts: 12
• Number of slices to send:
Optional 'thank-you' note:
Many Thanks to you all. It's perfectly clear now
Ian

 What's a year in metric? Do you know this metric stuff tiny ad? a bit of art, as a gift, that will fit in a stocking https://gardener-gift.com