LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Decimal to Binary to Hex howto (https://www.linuxquestions.org/questions/linux-newbie-8/decimal-to-binary-to-hex-howto-709426/)

Gortex 03-05-2009 12:14 PM

Decimal to Binary to Hex howto
 
After looking on line at the diffrent tutorials on decimal to hex conversions, I decided that they were overly complicated. So to help some new people out I thought I would show the easy way to do this.

Code:

Here is our decimal ip address 192.168.0.1

How to convert

 First start on a peace of paper and write out these numbers

128    64    32  16  8  4  2  1


what these are are the decimal values of the diffrent bits in an octet ( 8 bytes)

now on to the conversion

192

first step is start on the left hand side of our number list and subtract from the number

  192
- 128
=  64

so what I am going to do here is record that there was enough to subtact 128 from 192, by placing a 1 in the
128 slot

so now my table looks like this

128    64    32    16  8  4  2  1
 1

now I will subtract the next value from the remainder which is 64.

  64
-  64
    0
so now the table looks like this

128  64  32  16  8  4  2  1
 1    1

now their is nothing left to subtract so all your other values will = 0

now you have a binary address of  11000000

these numbers from an octet which is 8 bits. To convert from hex all you need to do is divide this in to two nibbles  (4 bits)
  niba  nibb
  1100  0000

the values work the same from the right hand side it is 1  2  4  8

so nible a has the 8 and the 4 place lit up add those two numbers togeather to come up with 12
12 in hex =  c

nible b has no places lit up so it is 0
0 in hex = 0

your hex value fro this number is  c0

now you have  192  in decimal  11000000 in binary  and c0 in hex.

now to convert hex in to decimal just follow these steps backwards....


c0

c = 12

    8  4  2  1

12 - 8 = 4
 
  8  4  2  1
  1

4 - 4 = 0

8  4  2  1
1  1  0  0


0 = 0

8  4  2  1
0  0  0  0

so now you have  11000000

take your old table  128  64  32  16  8  4  2  1
                        1  1    0  0  0  0  0  0
128  + 64  = 192

Now you know the easy way to convert between these bases.

once again the other tutorials I have found show you how to convert to hex by dividing by 16 much more complicated in my opinion. I hope this helps.

Tinkster 03-05-2009 01:23 PM

Ummm ... why do you post this in Newbie and not in our
tutorial section?

Gortex 03-05-2009 01:45 PM

wasn't paying attention sorry.

/shrug Just remove the thread.

H_TeXMeX_H 03-05-2009 02:12 PM

Ok, but why would you even need to do this by hand ? What I usually do if I ever have to do it by hand is make a table of binary to hex (and of course decimal fits on there too).

sundialsvcs 03-05-2009 02:15 PM

I keep my HP-16C calculator fresh with batteries for just this purpose ...

SISSIES FOR ITS NOT NOTATION POLISH REVERSE (... or something like that...)

Gortex 03-05-2009 02:45 PM

Quote:

Originally Posted by sundialsvcs (Post 3466120)
I keep my HP-16C calculator fresh with batteries for just this purpose ...

SISSIES FOR ITS NOT NOTATION POLISH REVERSE (... or something like that...)



can you use that calculator for the CCNA exam ?


Like I said if the information is not useful or in the wrong place just remove it.

Gortex 03-05-2009 02:54 PM

Quote:

Originally Posted by H_TeXMeX_H (Post 3466118)
Ok, but why would you even need to do this by hand ? What I usually do if I ever have to do it by hand is make a table of binary to hex (and of course decimal fits on there too).

if you follow the ccna guide lines on subnetting, this information is very useful. imo

Tinkster 03-05-2009 03:29 PM

I find it useful, it's just not a question, and hence in the wrong place.

Please submit it as a tutorial in the answers section (maybe after fixing the spelling) ;}.


Cheers,
Tink


All times are GMT -5. The time now is 01:48 AM.