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

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

please any anyone help me to convert hexadecimal and octal values to decimal
i know the vice a versa i.e. from decimal to hexadecimal ,octal

Sheriff
Posts: 17626
300
• Number of slices to send:
Optional 'thank-you' note:
For Decimal to Hex, just divide successively by 16, keeping the whole number result but noting the remainder of each division as you go, until you get a 0 result.
Take decimal 11948
11948 / 16 = 746 rem. 12
746 / 16 = 46 rem. 10
46 / 16 = 2 rem 14
2 / 16 = 0 rem 2
Then, go backwards through your list of remainders and convert each to hex. For this example, you will get 2EAC, which is the Hex representation of Decimal 11948
Same process when you convert Decimal to Octal, only your divisor will be 8.
For Hex to Decimal:
2EAC = (2 * 16^3) + (14 * 16^2) + (10 * 16^1) + (12 * 16^0) = 11948
When converting from Octal, use powers of 8.

[This message has been edited by JUNILU LACAR (edited June 21, 2001).]

Ranch Hand
Posts: 1492
• Number of slices to send:
Optional 'thank-you' note:
Hi Felix,
Its easy, as long as you can perform a power function and some multiplication.
Hex to Dec:
Values 0 to 9 translate directly, A - F map to 10 to 15
Generic formula:
Decimal subValue = Hex digit * (16 ^ digit position)
where digit position starts at zero in the rightmost position and increments by one as you go left.
Once you get all the subtotals then you just add them together.
Examples:
0x4321
1*16^0 + 2*16^1 + 3*16^2 + 4*16^4
1*1 + 2*16 + 3*256 + 4*4096
1 + 32 + 768 + 16384
17185
0x7D
13*16^0 + 7*16^1
13*1 + 7*16
125
Oct to Dec:
Use the same formula but you use 8 instead of 16.
Values 0 - 7 translate directly

Decimal subValue = Oct digit * (8 ^ digit position)
Examples:
076
6 * 8^0 + 7 * 8^1
6*1 + 7*8
6 + 56
62
0432
2 * 8^0 + 3 * 8^1 + 4 * 8^2
2*1 + 3*8 + 4*64
2 + 24 + 256
282
Regards,
Manfred.

Ranch Hand
Posts: 3141
• Number of slices to send:
Optional 'thank-you' note:
Hi Felix,
I have some notes on binary,octal,decimal, hexidecimal conversions posted at http://www.janeg.ca/scjp/oper/binhex.html
Hope they help.
------------------
Jane Griscti
Sun Certified Programmer for the Javaï¿½ 2 Platform

felix thomas
Ranch Hand
Posts: 89
• Number of slices to send:
Optional 'thank-you' note:
hi,
thanks a lot guys

 So I left, I came home, and I ate some pie. And then I read this tiny ad: a bit of art, as a gift, that will fit in a stocking https://gardener-gift.com