LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-05-2009, 01:14 PM   #1
Gortex
Member
 
Registered: Nov 2005
Location: Enid Ok
Distribution: ubuntu 64 , debian , fedora core , vista ultimate 64, Winows 7 64 ultimate :p
Posts: 219

Rep: Reputation: 30
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.
 
Old 03-05-2009, 02:23 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Ummm ... why do you post this in Newbie and not in our
tutorial section?
 
Old 03-05-2009, 02:45 PM   #3
Gortex
Member
 
Registered: Nov 2005
Location: Enid Ok
Distribution: ubuntu 64 , debian , fedora core , vista ultimate 64, Winows 7 64 ultimate :p
Posts: 219

Original Poster
Rep: Reputation: 30
wasn't paying attention sorry.

/shrug Just remove the thread.

Last edited by Gortex; 03-05-2009 at 02:48 PM.
 
Old 03-05-2009, 03:12 PM   #4
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285
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).
 
Old 03-05-2009, 03:15 PM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 7,151

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

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

Last edited by sundialsvcs; 03-05-2009 at 03:16 PM.
 
Old 03-05-2009, 03:45 PM   #6
Gortex
Member
 
Registered: Nov 2005
Location: Enid Ok
Distribution: ubuntu 64 , debian , fedora core , vista ultimate 64, Winows 7 64 ultimate :p
Posts: 219

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by sundialsvcs View Post
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.
 
Old 03-05-2009, 03:54 PM   #7
Gortex
Member
 
Registered: Nov 2005
Location: Enid Ok
Distribution: ubuntu 64 , debian , fedora core , vista ultimate 64, Winows 7 64 ultimate :p
Posts: 219

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by H_TeXMeX_H View Post
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
 
Old 03-05-2009, 04:29 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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

Last edited by Tinkster; 03-05-2009 at 04:30 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Decimal to binary conversion master General 10 12-21-2007 03:03 AM
how to convert binary fractions to decimal jabka Programming 12 12-16-2006 07:05 PM
Decimal to binary maldini1010 Programming 6 02-01-2005 05:03 PM
converting fake hex to decimal in c acid_kewpie Programming 10 08-20-2003 03:29 PM
c++ binary to decimal conversion.. miguetoo Programming 13 04-24-2003 10:49 PM


All times are GMT -5. The time now is 04:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration