# Learn and practice binary and hexadecimal numbers

## Recommended Posts

Over my years of learning programming, ive learned that binary and hexadecimal numbers are very important. I have learned each maybe once or twice but not enough to truly remember them. I am looking for a quality tutorial that you would recommend as a way to learn and practice binary/hex numbers. Thank you :)

##### Share on other sites
They work the same way "normal" base 10 numbers work.

If you want to set a given bit, use the left shift operator, and shift 1 to the left enough times, using bitwise or to set more than one bit.

To convert from decimal to dex or binary, use the windows calculator (or, alternatively, create your own small program... base changing is extremely easy).

##### Share on other sites
Alright. I forgot that this should go into the Math forum...

##### Share on other sites
Do you basically understand how they work?

There's no question of practicing them. They come up useful in a lot of situations, and after encountering those situations over and over, you just get used to them.

One useful thing to know -- every hex digit is 4 binary digits. This makes converting from hex to binary very easy/

##### Share on other sites
One of the more important things to realize is that each hex number is four bits. Memorizing hex 1-F is important.

##### Share on other sites
It's been a couple of years since I've done this, so I might be a little off, but to do it by hand you need to use the Euclidian algorithm. I'm sure if mathworld or a similar math website could show you the inner workings of the algorithm.

##### Share on other sites
As a sidenote, today in class I was doing a history assignment for "Chaper 11" and thought, we just did chapter ten, why are we going back to three? Then I laughed at myself and only I knew what was so funny.

Anyway, to actually kind of contribute, knowing them comes in handy. Understanding how they represent the underlying data is vital. Its good to understand that the system we count with is similar to words in that, no matter you call them, they still represent the same thing. When you are dealing with data in RAM for example, four bytes could hold 0xBAADF00D, 3131961357, or 1011 1010 1010 1101 1111 0000 0000 1101 . Those charactors are simply a system that is used to represent the data that is there.

Hopefully that made some sence... I think I tried to get way to deep just then...

Dwiel

##### Share on other sites
Quote:
 Original post by Tazzel3DAs a sidenote, today in class I was doing a history assignment for "Chaper 11" and thought, we just did chapter ten, why are we going back to three? Then I laughed at myself and only I knew what was so funny.

Nerd!! Just kidding [grin] I think that's funny as well.

##### Share on other sites
8-bit binary number: 11010101                     ||||||||           27 (128) -+|||||||           26 (64)  --+||||||           25 (32)  ---+|||||           24 (16)  ----+||||           23 (8)   -----+|||           22 (4)   ------+||           21 (2)   -------+|           20 (1)   --------+decimal number: 128 + 64 + 16 + 4 + 1 = 213
It's not difficult to convert binary to decimal at all, and after a while you can do it in your head.

Every 4-bit group represents 1 hex digit.
0000 - 00001 - 10010 - 20011 - 30100 - 40101 - 50110 - 60111 - 71000 - 81001 - 91010 - A (10)1011 - B (11)1100 - C (12)1101 - D (13)1110 - E (14)1111 - F (15)
So in the binary -> decimal example, 11010101, or 213, would be D5 in hex.

##### Share on other sites
I have binary numbers down pretty good now. I read John Selvia's tutorials on counting binary numbers on your fingers and it helps a lot in converting back and forth very quickly :) (but only up to 1023)

##### Share on other sites
01 // 1
10 // 2
11 // 3

The binary system is exactly like the decimal system, only you skip all numbers with the numbers 2 to 9 in them. Eg. 1,[2,3,4,5,6,7,8,9,]10,11,[12,13,14,...,97,98,99,]100,101,[102,...,109,]110,111, etc.

Hey btw, isn't that an original way to look at it? ;)

I would have made a table explaining how to convert, but I don't know how to on this board... good luck with it anyways!

Edit: Damn, this board gets replies so fast one can't write an answer without two other replies appearing in the mean time!

##### Share on other sites
Quote:
 Original post by ontheheapOne of the more important things to realize is that each hex number is four bits. Memorizing hex 1-F is important.

I've memorized 1-F, it's 0 I can never remember.

##### Share on other sites
Hey-
My binary tutorial is now at http://www.johnselvia.com/binary/, and I've added a hexadecimal tutorial as well. Glad it could be useful for some folks on here.
John Selvia

##### Share on other sites
Quote:
Original post by Fruny
Quote:
 Original post by ontheheapOne of the more important things to realize is that each hex number is four bits. Memorizing hex 1-F is important.

I've memorized 1-F, it's 0 I can never remember.
Yeah, I was going to say, don't forget zero :P

Hex is really only used as a shorthand for binary. Experienced programmers should immediately recall the binary for any hex digit, or vice versa. Ra has posted almost everything you need to know.

Hex <-> decimal is another matter, but it's rare to need to do this.

##### Share on other sites
Umm why is hexidecimal and binary important for programming? I learned it because my first c book taught them but I have yet to find a use for either of them.

##### Share on other sites
oooh, don't forget grey code:
0000:00001:10011:2 what now?0010:30110:40111:50101:60100:71100:81101:91111:A1110:B1010:C1011:D1001:E1000:F

##### Share on other sites
Quote:
 Original post by AinokeaUmm why is hexidecimal and binary important for programming? I learned it because my first c book taught them but I have yet to find a use for either of them.

uh, optimizing boolean expressions is one. Hell, I use it all the time.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628365
• Total Posts
2982273

• 10
• 9
• 13
• 24
• 11