PDA

Click to See Complete Forum and Search --> : Tutorial: Binary, hex and decimal .. oh my!


MsMittens
November 1st, 2001, 12:42 AM
After a little discussion with some users in IRC, I was asked on how I teach the conversation from hex to binary to decimal. So I've decided to post everything here along the lines that I usually teach in class.

First, let's look at binary. It is merely a 1 (on) or 0 (off). We see binary used in a variety ways from permissions (in unix) to tcp/ip addresses to attribute settings. (space out the bit so that a decimal appears under each 0)

0 0 0 0 0 0 0 0
128 64 32 16 8 4 2 1

So if my binary was like below:


0 1 1 0 1 1 0 0
128 64 32 16 8 4 2 1

This means that the bits 64, 32, 8, 4 are turned on totalling a value of 108 (64+32+8+4).

If you have to go beyond the 8 bits (the examples above are 8 bits as found in IPv4 addressing aka 32bit addressing --> 4x8bits), just continue doubling the numbers. So if I had to go to 12 bits (aka Fat12) I would have:

0 0 0 0 0 0 0 0 0 0 0 0
2048 1024 512 256 128 64 32 16 8 4 2 1

And so on.

Simple, eh? Now, how about Hex? Well Hex aka Hexadecimal is a "base-16" numbering system. Binary is a "base-2" (based on 2 digits) and decimal is "base-10" (based on 10 digits).

If I was to count in binary and decimal it would be:

Binary = Decimal
0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = 8
1001 = 9
1010 = 10
1011 = 11
1100 = 12
1101 = 13
1110 = 14
1111 = 15

So, now I can count easily from 0 to 15. Oh. Interesting. 16 digits. ;) We'll add the hex to the digit now.

Binary = Decimal = Hexadecimal
0000 = 0 = 0
0001 = 1 = 1
0010 = 2 = 2
0011 = 3 = 3
0100 = 4 = 4
0101 = 5 = 5
0110 = 6 = 6
0111 = 7 = 7
1000 = 8 = 8
1001 = 9 = 9
1010 = 10 = A
1011 = 11 = B
1100 = 12 = C
1101 = 13 = D
1110 = 14 = E
1111 = 15 = F

So now I can go from binary to decimal to Hex. This little chart is easy to setup and handy to have. Once you have this the rest is straightforward. An example:

0 1 1 0 1 0 1 0 1 1 1 0
2048 1024 512 256 128 64 32 16 8 4 2 1

Notice that there are 12 bits. Seperate your bits into groups of 4 like so:

0 1 1 0 1 0 1 0 1 1 1 0

And do the hex for each (hex is easier than decimal). This example would come out to:

6 A E

Sometimes written as 6AExh. Now do the decimal:

0 1 1 0 1 0 1 0 1 1 1 0
2048 1024 512 256 128 64 32 16 8 4 2 1

So, 1024+512+128+32+8+4+2 = 1,710(barring any addition errors that should be it). Most of my students get errors in the decimal portion due to addition errors. Give it a try and its best to do it a few times on paper to practise. Once you get that down, it will be straightforward after that.

If you want some more examples, let me know and I will put some more up.

Hope this helps.

aarobonob
November 1st, 2001, 12:58 AM
i hope you write tutorials...thanx for the mini-lesson... although i knew this already, i encourage you to make tutorials and such and perhaps start your own website? cuz then, you know, you could shamelessly promote your website here too, like adore from hackers does:)

MsMittens
November 1st, 2001, 01:04 AM
Thank you. As I come up with more things that are needed and that I have some clue about I will post accordingly. ;)

Is there something that you'd like to see a tutorial about?

aarobonob
November 1st, 2001, 01:08 AM
not any specifics... i just was trying to encourage you. its nice to see people who take the initiative to share information.

aarobonob
November 1st, 2001, 04:44 PM
how a bout a quick and down and dirty java tutorial? i have the class now and i'm learning the why's but its a little slow on the what to do if you wanna... stuff.. does that make sense ? :)

MsMittens
November 1st, 2001, 08:00 PM
Java, unfortunately, ain't my speciality. But if you ask in the Security Programming forum perhaps someone there might be able to help.

I tend to be more network admin oriented. I'm working on my programming these days.

psyk0path
November 1st, 2001, 11:07 PM
how about... subnetting?

MsMittens
November 1st, 2001, 11:17 PM
Ok.. I will work on that one over the weekend and see what I can come up. ;)

Subnetting, the lost art and also it's evil twin, supernetting. ;)

intruder
November 3rd, 2001, 09:36 AM
hey greate job mittens....i learned a lot...good job...
and thanks for the tutorial ...

hey mittens..if u know assembly why don't u write something on it and post....i am sure that will help a lot..

thanks once again..

intruder... :borg:

Kezil
November 3rd, 2001, 08:03 PM
How 'bout mathematical operations in hex and binary? addition, subtraction, multiplication, division, etc. I work on it in my free time, but school takes up most of it and anionline and learning programming the rest.

Thanks for the excellent binary/decimal/hex basics, too.:D

freon
November 7th, 2001, 07:10 PM
It might be fun also to cover octal - it's still useful you know! Possibly extend this tutorial to cover the representation of different types of data, like floating point (mantissa and exponent) notation for numeric quantities with a fractional part, two's complement for negative numbers, etc. Also, discussion of storage of textual data (ASCII and EBCDIC) and possibly some kind of description of BCD, could be useful to newbies.

Just a thought,

- Freon

viruss
November 22nd, 2001, 03:14 AM
It's really good stuff..

:cool:

hehbris
November 22nd, 2001, 02:41 PM
aarobonob

many java tutorials exist
http://java.sun.com is a wealth of information, the entire java api can be found online there and they also have many trails of tutorials covering every single aspect of the language in a not so hard format. Asking specific questions in the forum on that page will also result in answers that are probably better than what your teacher could ever explain.

mouse
November 23rd, 2001, 07:02 PM
thank you verry much for this tur. you just earned 1 big antipoitnt for this :) keep up the good work.

gilgalad
November 23rd, 2001, 07:31 PM
Very sweet tutorial...been looking for stuff on binary and hex...and this info was direct and to the point :cool:

shkuey
November 24th, 2001, 05:54 AM
An easy way to work with these numbers is to convert them to base 10, the standard we use to count. Simply take the base to the power of each numbers position - 1, and multiply by the number, then add them together.

19B in hex, is 1(16^2) + 9(16^1) + 11(16^0) = 411

If anyone can understand that from my explanation I'll be surprised, I don't articulate too well.

mountainman
December 20th, 2001, 12:34 AM
Hey I gots a subnetting tutorial written up already. Let me know if anyone is interested and I will post it.

Mr.Fatal
January 2nd, 2004, 04:19 PM
Yeah nice job on the tutorial i agree you should have your own site. We need more imformative sites.

jin29_neci
September 12th, 2004, 08:50 AM
thanks MsMittens for this mini-tutorials things. I think it will be more helpful if you will teach us to become a admin oriented like you. I myself is just hardware oriented only more on repairs.
In hardware products, printers and monitors.
Thanks anyway this tutorials give me at least a refersh.

muert0
September 12th, 2004, 08:57 AM
Heh. You brought up a thread that was last posted in in January. And the guy before you brought it up two years after the last post.
If you want to say something like thank you use the AP system that's what it's there for.

hexadecimal
September 12th, 2004, 12:31 PM
i knew my nickname had some importance in computers....i just couldnt remember for the life of me what it was....

great tut MsM :D