Ok, Here's the Lesson... Pay Attention... There's Going to Be a Test...






Base2, uses zero and one (0 & 1) as values.  Each value is known as a "bit".  The usual notation is with 8 bits, called a byte.  Byte notation is as below:

10011101 = 157

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

because 128 + 16 + 8 + 4 + 1 = 157.  So converting binary to decimal is as easy as counting by factors of two.

Here are some more conversions, see if you can work them out.  (answers at the end)

Binary Conversions (Exercise #1)
#1 - 10111101
#2 - 11111110
#3 - 00111100
#4 - 00000010
#5 - 10010010
#6 - 00001010
#7 - 01010101
#8 - 10011001

Ok, now that you have that down, you can see that making any representative number from 0 to 255 (a total of 256 values) can be represented in one byte (8 bits).

If you need larger values, you can represent numbers in even higher bit counts, or even larger byte counts.  (64bit computing is currently available, meaning that the processor can read, write, and compute 64bit numbers natively).

Another method that is used to represent numbers in computers, is base16, or hexadecimal.  Hex, for short.  It is represented in many different ways, normally as seen here:

0x93
0x01

The preceeding "0x" is to note that the following number, 93, and 01, respectively, are base 16 numbers.

Base 16 uses the following representative numbers below:

|  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  A  |  B  |  C  |  D  |  E  |  F  |

So, a hex value of 0xAA is acceptable. As is 0xDEADBEEF, as is 0xDC0DE

But, how do we convert Hex to Decimal (Base10)?

Well, we could start counting up the value in each column, noting that they increase by factors, or we could just use binary and "cheat".  First, let's do it the hard way...

Hex  -> Decimal
0x00 = 0
0x01 = 1
0x02 = 2
... all the way up to
0x09 = 9
0x0A = 10
0x0B = 11
0x0C = 12
0x0D = 13
0x0E = 14
0x0F = 15

Which is a total of 16 values, or base 16.

but what happens when we increment the values even more?

0x10 = (1x16 + 0) = 16
0x15 = (1x16 + 5) = 21
0x19 = (1x16 + 9) = 25

or

0x97 = (9x16 + 7) = 151

Are you with me yet?

Ok, now that you've got that... it's time for another exercise.

Hexadecimal Conversion (The hard way, Exercise 2)
#1 - 0x9F
#2 - 0xFA
#3 - 0xDE
#4 - 0xAA
#5 - 0x63
#6 - 0x10
#7 - 0x39
#8 - 0x42

Ok... now that you have that down, I'm going to show you the easy way to convert Binary -> Hex -> Decimal... I find it much faster.

So, we take a binary number, and break it up into two sets of four bits...

10110010 --> 1011 0010

Now, we apply binary rules to each of the four bits... meaning we're going to treat them as just two four bit numbers. (by the way, this is octal, or base 8)
b2 --> decimal
1011 =  8 + 2 + 1 = 11
0010 = 2

Now, we can take those and convert to Hex, simply by notating in Hex, the value of 11, then the value of 2.  (remember, 11 = B)

  Binary: 1011 0010
      Hex:    B       2
Decimal:
and by the power of math... you can quickly figure that the value of 10110010 is 0xB2, or (11x16 + 2) or 178.

You can do this in many different forms... so, enjoy...




=========================Answers Below=========================























Binary Conversions (Exercise #1)
#1 - 10111101 = 189
#2 - 11111110 = 254
#3 - 00111100 = 60
#4 - 00000010 = 2
#5 - 10010010 = 146
#6 - 00001010 = 10
#7 - 01010101 = 85
#8 - 10011001 = 153

Hexadecimal Conversion (The hard way, Exercise 2)
#1 - 0x9F = (9x16 + 15) = 159
#2 - 0xFA = (15x16 + 10) = 250
#3 - 0xDE = (13x16 + 14) = 222
#4 - 0xAA = (10x16 + 10) = 170
#5 - 0x63 = (6x16 + 3) = 99
#6 - 0x10 = (1x16 + 0) = 16
#7 - 0x39 = (3x16 + 9) = 57
#8 - 0x42 = (4x16 + 2) = 66
dc0de dc0de
41-45, M
9 Responses Jul 7, 2007

Me too. I think of (1) as "yes" or "on" and (0) as "no" or "off". I only understand numbers, Im 12 years old. I bet nobody in the entire school, not even the teachers, understand binary or even know what it is. I asked my friend and she never even heard of it. She claims she is a "computer expert". "Some computer expert you are."

Shaylon<br />
positive(1) means you do add it to the total value, where as negative(0) you don't add to total

10110010 --> 1011 0010<br />
<br />
Now, we apply binary rules to each of the four bits... meaning we're going to treat them as just two four bit numbers. (by the way, this is octal, or base 8)<br />
<br />
<br />
by the way it is not octal<br />
it is 8bit binary code splited in 2x4bits..<br />
octal would be 010 110 010.. why?<br />
octal = 8 digits (0-7) max digit octal value is 7 = 111 binary<br />
so code is splited in Nx3bits, and hex is 15 max value<br />
witch is binary 1111 so u need 4 bits, and that is why u when calculate binary to hex, split binary every 4bits..<br />
<br />
all of u say:<br />
| 8 | 4 | 2 | 1 |<br />
| 1 | 1 | 1 | 1 | == 15 <br />
<br />
it is not wrong but it is wrong way to learn it..<br />
why 8, why 4, why 2, why 1, why 32 and why every 2^n?<br />
<br />
4 | 3 | 2 | 1 | 0 | index of exponent (n)<br />
1 | 1 | 1 | 1 | 0 | == 31<br />
<br />
1*2^4 + 1*2^3 + 1*2^2 + 1*2^1 + 0*2^0 =<br />
16+8+4+2+0 = 31<br />
<br />
hope u get it all:)<br />
cheers

Shaylon, <br />
<br />
binary can be elusive. Take a look at this number:<br />
<br />
binary Decimal<br />
0001 == 1<br />
0011 == 3<br />
0111 == 7<br />
1111 == 15<br />
<br />
Because the binary values in each subsequent column represent this: <br />
<br />
Column<br />
| 8's | 4's | 2's | 1's | <br />
| 1 | 1 | 1 | 1 | == 15 <br />
<br />
because (1x8)+(1x4)+(1x2)+(1x1) = 15<br />
<br />
if it were 0101, that equals (0x8)+(1x4)+(0x2)+(1x1)=5<br />
<br />
Hopefully this clears it up for you.

I get the part about binary code being 01 as either a negative or positive value. The numbers that you came up with for the combinations would seem somewhat illusive with this explanation to me.

Oh, all of my math class fears are coming back...

Ah, binary codes are nice! :D It can be used for solving math questions like these: "A function f is defined on the positive integers by: f(1) = 1; f(3) = 3; f(2n) = f(n), f(4n + 1) = 2f(2n + 1) - f(n), and f(4n + 3) = 3f(2n + 1) - 2f(n) for all positive integers n. Determine the number of positive integers n less than or equal to 1988 for which f(n) = n. " - IMO 1988, question A3

LOL, Soditzy.:)

have just lost the will to live....1+1 = hell, isnt that all anyone needs to know