Quick Tutorial of how to convert decimal into hexadecimal (in 5 minutes or less)

balcobullsbalcobulls Member Posts: 25 ■□□□□□□□□□
First off, why in the heck do you need to know how to convert into hexadecimal? The answer is....it depends.
Do you think you might be sniffing networks one day? Or maybe you sniff networks already but do not really care about the hexadecimal displayed at the bottom of Wireshark? Or maybe you just want to learn? My goal is to take five minutes or less of your time and teach you a very simple conversion that most people avoid.
Let's start!
  • I am going to pick a random number.......lets say 1154
  • Now the number 16 is very very very very important for hex, you will see why. (16, in case you forgot the number already)
  • 1154 will be divided by 16
(don't worry I have a calculator so I'll do the math)
  • Answer = 72.125
  • The magic comes with the "remainder not the actual result." So lets take the 72 and put it aside for a second, we are going to focus on the .125
(remember that 16 number? Told ya its important)
  • .125 will be multiplied by 16
  • Answer = 2
(if you haven't already, open up the attachment named "Hex Table.doc")
  • 2= 2 in hex
  • Now we will bring back the 72, we will now continue to divide this number by 16
  • Answer = 4.5
(Remember we will stash 4 away for a few moments and only worry about the .5)
  • .5 x 16 = 8
  • 8 in hex = 8
(We will now bring that 4 back into the picture)
  • 4 / 16 = .25
(Now we do not have to worry about any whole numbers only the decimal)
  • .25 x 16 = 4
  • 4 in hex = 4
(Now from all of these equations, to make sure all of your work is correct, you will read from your MOST RECENT answer to the VERY FIRST answer you received)
  • Most recent answer we got in hex was 4,
  • Previous to that 8
  • And our first hex answer was 2
Drum roll please................................
1154 in hexadecimal is 482
Its that easy! If you have not opened the attachment, FYI any hex equivalent after you get above the number 9 turns into a letter. Example Below:
1=1
2=2
3=3
4=4
5=5
6=6
7=7
8=8
9=9
10=A
11=B
12=C
13=D
14=E
15=F
(15 is the highest you can go when it comes to hex)

I hope this didn't take more than five minutes like I advertised at the beginning, if so...I'm kinda sorry.

Now go about your day and go brag to your friends that you know hexangel.png

Comments

  • TWXTWX Member Posts: 275 ■■■□□□□□□□
    I think that I can make it faster, using long-division and remainders.

    let's 3345...
        
        [U] 209[/U]  R1
    16 |3345
        [U]-32[/U]
         145
        [U]-144[/U]
           1
    

    So 1 is the in the units column.
        [U] 13[/U] R1
    16 |209
       [U]-16[/U]
         49
        [U]-48[/U]
          1
    

    Another one in the units column, so 11 so far...
    13 < 16
    
    13=D
    

    D11.

    I did not check this on a calculator until after I got the answer, and when I did check it it looks to be valid.
  • ExpectExpect Member Posts: 252 ■■■■□□□□□□
    wondering why not just use Python's hex function? :) is there any purpose for the calculations?

    >>> a = 3345
    >>> hex(a).split('x')[1]
    'd11'
  • TWXTWX Member Posts: 275 ■■■□□□□□□□
    Let's do another .... 2797
        [U] 174[/U] R13
    16 |2797
       [U]-16[/U]
        119
       [U]-112[/U]
          77
         [U]-64[/U]
          13
    

    13=D
        [U] 10[/U] R14
    16 |174
       [U]-16[/U]
         14
        [U]- 0[/U]
         14
    

    14=E, so ED
    10 < 16
    
    10=A
    
    

    The answer is AED
  • TWXTWX Member Posts: 275 ■■■□□□□□□□
    Expect wrote: »
    wondering why not just use Python's hex function? :) is there any purpose for the calculations?

    >>> a = 3345
    >>> hex(a).split('x')[1]
    'd11'

    There is no Python hex function on a certification exam, or at least not on the Cisco ones.
  • ExpectExpect Member Posts: 252 ■■■■□□□□□□
    I see, didn't realize this is for a specific certification.
  • TWXTWX Member Posts: 275 ■■■□□□□□□□
    Now, hex to decimal.. BEEF...

    first each digit to its hex...
    BEEF
    
    11, 14, 14, 15
    

    Now each times sixteen to the power of the column minus one (ie, 16x-1) or if you can remember it, the units column is 160...
     11*(16[SUP]3[/SUP])
     14*(16[SUP]2[/SUP])
     14*(16[SUP]1[/SUP])
     15*(16[SUP]0[/SUP])
    
    

    now, 16 to the power of, to refer to...
      16
     [U]*16[/U]
      96
    [U]+16 [/U]
     256
    
      256
      [U]*16
    [/U] 1536
    [U]+256 
    [/U] 4096
    

    Now combine...
      4096
      [U]* 11[/U]
      4096
    [U]+4096 [/U]
     45056
    
      256
      [U]*14[/U]
     1024
    [U]+256 [/U]
     3584
    
      16
     [U]*14[/U]
      64
    [U]+16 [/U] 
     224
    
    15
    
    

    Now to sum-up...
    45056
     3584
      224
    [U]+  15[/U]
    48879
    
    

    It's a PITA but it's doable if needed.
  • TWXTWX Member Posts: 275 ■■■□□□□□□□
    Expect wrote: »
    I see, didn't realize this is for a specific certification.

    Quite honestly I don't know if any certification exam would have this kind of math, but there are cases for binary to decimal in the Cisco exams. Given this an exam-oriented website, figured showing how to do it without a calculator wasn't a bad thing.

    Sorry I hijacked your thread, balcobulls...
  • balcobullsbalcobulls Member Posts: 25 ■□□□□□□□□□
    Perfectly fine TWX!.....that is what forums are for, even if I wrote it I need to learn from other examples. So thank you for contributing! The CEH requires you to know how to convert into Hex mainly for Wireshark, I have only seen one question ever on hex on the CEH, but still there is one floating around.
  • OctalDumpOctalDump Member Posts: 1,722
    Are there exams with calculators that don't have dec <-> hex functionality?

    I just figured your example 1154 is 1024 + 130 which is 1024 + 128 + 2 or 4x 256 + 8x 16 + 2 - 482. Probably took just as long as punching numbers into a calculator. As Eichman says, mathematics is done with pencil and paper.

    The 3345 example, is 13x256 + 16 + 1 - D11
    The 2797 example is 10x256 + 14x 16 + 13 - AED

    I just use the general method I was taught in high school for converting bases. Powers of 16 are easy if you know powers of two. It's just every 4th power.

    Whatever works, and having more than one trick up your sleeve helps.
    2017 Goals - Something Cisco, Something Linux, Agile PM
  • TWXTWX Member Posts: 275 ■■■□□□□□□□
    I can't recall having learned number base conversion in school in a mathematics course. We might have just touched on it in a computer programming class, but not really used it for anything. A shame really.
  • OctalDumpOctalDump Member Posts: 1,722
    TWX wrote: »
    I can't recall having learned number base conversion in school in a mathematics course. We might have just touched on it in a computer programming class, but not really used it for anything. A shame really.

    Oh you haven't lived until you've done a few pages of exercises converting numbers between different bases by hand (and showing all your working). icon_lol.gif
    2017 Goals - Something Cisco, Something Linux, Agile PM
  • TWXTWX Member Posts: 275 ■■■□□□□□□□
    OctalDump wrote: »
    Oh you haven't lived until you've done a few pages of exercises converting numbers between different bases by hand (and showing all your working). icon_lol.gif

    You know, I hated long-division as a kid too, but I use it regularly now, and arguably I use the most basic version where remainders are left in the answer instead of continuing to divide against them to a degree of significance like the sciences would normally want.
  • PristonPriston Member Posts: 999 ■■■■□□□□□□
    1154-1024=130
    130-128=2
    2-2=0
    0100 1000 0010
    4 8 2

    3345-2048=1297
    1297-1024=273
    273-256=17
    17-16=1
    1-1=0
    1101 0001 0001
    d 1 1


    BEEF
    1011 1110 1110 1111
    (32768+8192+4096)+(2048+1024+512)+(224+15)
    45056+3584+239
    48879
    A.A.S. in Networking Technologies
    A+, Network+, CCNA
Sign In or Register to comment.