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

# Converting Hex to decimal?

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
 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
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
 Better late than never... (13 items)
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
 Better late than never... (13 items)
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
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
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
 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
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
Sorry I thought you wanted to convert decimal to hex.
What tompsonn said is the correct way.
 Better late than never... (13 items)
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
 Better late than never... (13 items)
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
Quote:
Originally Posted by KaMeNoS

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

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

Sorry I thought you wanted to convert decimal to hex.
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
 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
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? If you answered "thats' the maximum number for a 32-bit unsigned integer", then you're good to go

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
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
 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
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
Quote:
Originally Posted by tompsonn

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? If you answered "thats' the maximum number for a 32-bit unsigned integer", then you're good to go
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
 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
 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
Quote:
Originally Posted by [xPt]FLuX

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

Cheers mate, but I think if I did that all day I'd get super impatient
 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
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
 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
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
New Posts  All Forums:Forum Nav:
Return Home
Back to Forum: Coding and Programming
• Converting Hex to decimal?
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Converting Hex to decimal?