Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Converting Hex to decimal?
New Posts  All Forums:Forum Nav:

Converting Hex to decimal?

post #1 of 8
Thread Starter 
Hi,

Im writing a test on basic IT principles tomorrow and one of the tasks is converting hex/binary to decimal.
I can readily convert binary to decimal and vice versa but im having trouble with hex, i dont understand the way it works with numbers and letters?

can someone help me convert it to decimals?
Teh YayZors!
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.3GHz Gigabyte GA-P67A-UD4-B3 (Revision) AMD 6950 [unlocked to 6970] G.Skill RipJaws X 4GB (2 x 2GB) 1600mhz + Kings... 
Hard DriveOptical DriveOSMonitor
OCZ 460A 120GB SSD + 1TB 2x Optical  Windows 7 64-bit | Ubuntu 15.10 24" Samsung SyncMaster BX2450 
PowerCase
Corsair HX850W Coolermaster CM690 II Advanced 
  hide details  
Reply
Teh YayZors!
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.3GHz Gigabyte GA-P67A-UD4-B3 (Revision) AMD 6950 [unlocked to 6970] G.Skill RipJaws X 4GB (2 x 2GB) 1600mhz + Kings... 
Hard DriveOptical DriveOSMonitor
OCZ 460A 120GB SSD + 1TB 2x Optical  Windows 7 64-bit | Ubuntu 15.10 24" Samsung SyncMaster BX2450 
PowerCase
Corsair HX850W Coolermaster CM690 II Advanced 
  hide details  
Reply
post #2 of 8
To convert a Decimal number to Hex, first convert it to binary, then split it at 4 digit chucks. After you do that you convert each chunk to the Hex equivilant. You start splitting from the right to the left. if the last digits aren't 4 you fill with zeroes.

Example:
Code:
2972(10) = 101110011100(2)
1011 = B(16), 1001 = 9(16), 1100 = C(16) = B9C(16)

Edited by KaMeNoS - 1/30/12 at 7:56am
    
CPUMotherboardGraphicsRAM
Xeon X5650@4GHz Asus P6T Deluxe Asus GTX760@1254/3305MHz 12GB HyperX@1600MHz CL9 
Hard DriveHard DriveOptical DriveCooling
Seagate 7200.12 1TB (Storage) ExcelStor J8160S 160GB (OS/Programs/Games) Optiarc AD-7203S Scythe Mugen Rev. B 
OSMonitorPowerCase
Windows 7 64bit LG IPS234V 23" 1080p XFX PRO 550W Tt Soprano 
Audio
ADI2000B 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Xeon X5650@4GHz Asus P6T Deluxe Asus GTX760@1254/3305MHz 12GB HyperX@1600MHz CL9 
Hard DriveHard DriveOptical DriveCooling
Seagate 7200.12 1TB (Storage) ExcelStor J8160S 160GB (OS/Programs/Games) Optiarc AD-7203S Scythe Mugen Rev. B 
OSMonitorPowerCase
Windows 7 64bit LG IPS234V 23" 1080p XFX PRO 550W Tt Soprano 
Audio
ADI2000B 
  hide details  
Reply
post #3 of 8
Converting from hex to decimal all you have to do is multiply 16 with the second digit and to the left, plus the remainder.

If we had a hex number 5A and we wanted to convert it to decimal, we would do first:

16 * 5 = 80

Then we have the remainder, which is A, converting that to decimal is easy as it is just 10, so we add 80 + 10 which gives us 90.
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #4 of 8
Sorry I thought you wanted to convert decimal to hex. doh.gif
What tompsonn said is the correct way.
    
CPUMotherboardGraphicsRAM
Xeon X5650@4GHz Asus P6T Deluxe Asus GTX760@1254/3305MHz 12GB HyperX@1600MHz CL9 
Hard DriveHard DriveOptical DriveCooling
Seagate 7200.12 1TB (Storage) ExcelStor J8160S 160GB (OS/Programs/Games) Optiarc AD-7203S Scythe Mugen Rev. B 
OSMonitorPowerCase
Windows 7 64bit LG IPS234V 23" 1080p XFX PRO 550W Tt Soprano 
Audio
ADI2000B 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Xeon X5650@4GHz Asus P6T Deluxe Asus GTX760@1254/3305MHz 12GB HyperX@1600MHz CL9 
Hard DriveHard DriveOptical DriveCooling
Seagate 7200.12 1TB (Storage) ExcelStor J8160S 160GB (OS/Programs/Games) Optiarc AD-7203S Scythe Mugen Rev. B 
OSMonitorPowerCase
Windows 7 64bit LG IPS234V 23" 1080p XFX PRO 550W Tt Soprano 
Audio
ADI2000B 
  hide details  
Reply
post #5 of 8
Thread Starter 
Quote:
Originally Posted by KaMeNoS View Post

To convert a Decimal number to Hex, first convert it to binary, then split it at 4 digit chucks. After you do that you convert each chunk to the Hex equivilant. You start splitting from the right to the left. if the last digits aren't 4 you fill with zeroes.
Example:
Code:
2972(10) = 101110011100(2)
1011 = B(16), 1001 = 9(16), 1100 = C(16) = B9C(16)
Quote:
Originally Posted by tompsonn View Post

Converting from hex to decimal all you have to do is multiply 16 with the second digit and to the left, plus the remainder.
If we had a hex number 5A and we wanted to convert it to decimal, we would do first:
16 * 5 = 80
Then we have the remainder, which is A, converting that to decimal is easy as it is just 10, so we add 80 + 10 which gives us 90.
Quote:
Originally Posted by KaMeNoS View Post

Sorry I thought you wanted to convert decimal to hex. doh.gif
What tompsonn said is the correct way.


Wow, thanks so much guys I didnt realise it was so easy haha but +rep to u
Teh YayZors!
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.3GHz Gigabyte GA-P67A-UD4-B3 (Revision) AMD 6950 [unlocked to 6970] G.Skill RipJaws X 4GB (2 x 2GB) 1600mhz + Kings... 
Hard DriveOptical DriveOSMonitor
OCZ 460A 120GB SSD + 1TB 2x Optical  Windows 7 64-bit | Ubuntu 15.10 24" Samsung SyncMaster BX2450 
PowerCase
Corsair HX850W Coolermaster CM690 II Advanced 
  hide details  
Reply
Teh YayZors!
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.3GHz Gigabyte GA-P67A-UD4-B3 (Revision) AMD 6950 [unlocked to 6970] G.Skill RipJaws X 4GB (2 x 2GB) 1600mhz + Kings... 
Hard DriveOptical DriveOSMonitor
OCZ 460A 120GB SSD + 1TB 2x Optical  Windows 7 64-bit | Ubuntu 15.10 24" Samsung SyncMaster BX2450 
PowerCase
Corsair HX850W Coolermaster CM690 II Advanced 
  hide details  
Reply
post #6 of 8
And just to make it even more confusing, say we had hex number 3E5 and we wanted to convert to decimal, we would do:

( 3 * 256 ) + ( 14 * 16 ) + 5 which is 997.

Where the hell did I get 16 and 256 from? Well, in hex each place value is a consecutive power of 16. The 5 is in the one's place so we leave him alone, the E (with decimal value of 14, which is A or 10 in decimal + 4) is in the 16's place, and the 3 is in the 256's place.

All we do is multiply the decimal or hex decimal value by its place value and then keep adding.

Exercise? What would FFFFFFFF be in decimal? tongue.gif If you answered "thats' the maximum number for a 32-bit unsigned integer", then you're good to go thumb.gif

And because I am in a math mood tonight...
Code:
5AFC

C = 1
F = 16
A = 256
5 = 4096


5 * 4096 = 20480
A or 10 * 256 = 2560
F or 15 * 16 = 240
C or 12 * 1 = 12

5AFC = 23292

And to make it even more fun, we see that each set of two in a hex number is actually a byte... We can fit 255 into a byte (( 16 * 15 ) + 15), so FF in hex doesn't need any special math as all 8 bits are set (4 bits set on each F for 15) which gives us 255.
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #7 of 8
Thread Starter 
Quote:
Originally Posted by tompsonn View Post

And just to make it even more confusing, say we had hex number 3E5 and we wanted to convert to decimal, we would do:
( 3 * 256 ) + ( 14 * 16 ) + 5 which is 997.
Where the hell did I get 16 and 256 from? Well, in hex each place value is a consecutive power of 16. The 5 is in the one's place so we leave him alone, the E (with decimal value of 14, which is A or 10 in decimal + 4) is in the 16's place, and the 3 is in the 256's place.
All we do is multiply the decimal or hex decimal value by its place value and then keep adding.
Exercise? What would FFFFFFFF be in decimal? tongue.gif If you answered "thats' the maximum number for a 32-bit unsigned integer", then you're good to go thumb.gif
And because I am in a math mood tonight...
Code:
5AFC
C = 1
F = 16
A = 256
5 = 4096
5 * 4096 = 20480
A or 10 * 256 = 2560
F or 15 * 16 = 240
C or 12 * 1 = 12
5AFC = 23292
And to make it even more fun, we see that each set of two in a hex number is actually a byte... We can fit 255 into a byte (( 16 * 15 ) + 15), so FF in hex doesn't need any special math as all 8 bits are set (4 bits set on each F for 15) which gives us 255.

wow really regretting missing that lesson now, but I think I understand it now - You should be a teacher bro thumb.gifwink.gif
Teh YayZors!
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.3GHz Gigabyte GA-P67A-UD4-B3 (Revision) AMD 6950 [unlocked to 6970] G.Skill RipJaws X 4GB (2 x 2GB) 1600mhz + Kings... 
Hard DriveOptical DriveOSMonitor
OCZ 460A 120GB SSD + 1TB 2x Optical  Windows 7 64-bit | Ubuntu 15.10 24" Samsung SyncMaster BX2450 
PowerCase
Corsair HX850W Coolermaster CM690 II Advanced 
  hide details  
Reply
Teh YayZors!
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.3GHz Gigabyte GA-P67A-UD4-B3 (Revision) AMD 6950 [unlocked to 6970] G.Skill RipJaws X 4GB (2 x 2GB) 1600mhz + Kings... 
Hard DriveOptical DriveOSMonitor
OCZ 460A 120GB SSD + 1TB 2x Optical  Windows 7 64-bit | Ubuntu 15.10 24" Samsung SyncMaster BX2450 
PowerCase
Corsair HX850W Coolermaster CM690 II Advanced 
  hide details  
Reply
post #8 of 8
Quote:
Originally Posted by [xPt]FLuX View Post

wow really regretting missing that lesson now, but I think I understand it now - You should be a teacher bro thumb.gifwink.gif

Cheers mate, but I think if I did that all day I'd get super impatient tongue.gif
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Converting Hex to decimal?