• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

hexadecimal and octal numbers

 
Greenhorn
Posts: 12
  • 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 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
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
the Hexadecimal equivalent is
0x13
-----------------------------------------------------------
thanks
Sathi


 
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ian,

If your converting from octal or hexadecimal it's easy.
So if you have say 0137:
In decimal this equals 7*8^0 + 3*8^1 + 1*8^2 = 95
If you had 0x137 :
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many Thanks to you all. It's perfectly clear now
Ian
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic