Hockeyplaya55′s Weblog


Binary Tutorial Part 2
December 16, 2008, 5:43 pm
Filed under: Uncategorized

Binary Tutorial Part 2

 

            There are Binary number stuff and ya there are numbers and stuff involved so here. These are tables and words that describe this binary number stuff.

 

The number system that you use is base 10 (since people have 10 fingers, this works out well for them). When you write the number 1853, for example it means:

Each digit (0-9) within a base 10 number is multiplied by the power of ten corresponding to its position. Notice that each digit place has 10 times the value of the digit place to the right of it. But you knew all this, of course.

Binary Numbers

But what of the poor computer, which has no fingers to count on? Base 10 is not convenient for a fingerless computer to use. What computers DO have, are electrical circuits, which are either on or off. Just two states to work with. So the natural number system for use in an electronic computer is base 2 (called the binary number system). Unlike you who have ten digits to calculate with (0, 1, 2, 3, 4, 5, 6, 7, 8, 9), the computer has only two digits (0 and 1) with which it must do everything. So, in a computer’s memory, a tiny transistor that is on (conducting a current) might represent a 1, while a transistor that is off would represent a 0 (zero).

The binary number 11100111101, for example, means:

Ah! So they are the same number!

1853 (base 10)  =  11100111101 (base 2)

Notice that each binary digit position in the base 2 number has 2 times the value of the binary digit position to the right of it (since this is base 2; remember how base 10 worked).

It gets cumbersome saying “binary digit” all the time, so the shorter term “bit” was invented. A bit is one binary digit. A bit can hold either a 1 or a 0 (zero). A string of bits can hold larger numbers (just as you use strings of base 10 digits to represent numbers larger than 9).

Binary Representation of Numbers

Base 10

Base 2

0

00000000

1

00000001

2

00000010

3

00000011

4

00000100

5

00000101

65

01000001

66

01000010

67

01000011

254

11111110

255

11111111

 

A particularly handy size chunk of computer memory happens to be 8 bits long. This size chunk of memory can be used to represent any number from zero (00000000) to 255 (11111111). Why does 11111111 (base 2) equal 255 (base 10)? Because it means:

1 x 128  +  1 x 64  +  1 x 32  +  1 x 16  + 
1 x 8  +  1 x 4  +  1 x 2  +  1 x 1  =  255

And why is this a handy size chunk of memory? Because if we want to represent all of the characters of the English alphabet, 8 digits is the first power of 2 that gives you enough possibilities to do this (a 4-bit long chunk can only hold numbers from zero to 7…not enough).

We have a special name for a chunk of memory that is 8 bits long: it is called a byte. This is the basic unit we use to measure computer memory size. (A chunk of memory 4 bits long is called a “nybble,” but you don’t need to know that for the test.)

Text characters are represented in computer memory as numbers. How? You need a scheme for equating letters to numbers. The system used is called the ASCII code (American Standard Code for Information Interchange). The capital letter A is represented by the number 65 in the ASCII code (65 is 01000001 in binary). The first 65 ASCII codes (0 through 64) are used for an assortment of Control characters and special characters, so capital A ended up at 65. Capital B is 66 (01000010) and so on.

ASCII Representation of Characters (just a sample)

Character

Base 10

Base 2

(return)

13

00001101

(space)

32

00100000

!

33

00100001

1

49

00110001

2

50

00110010

@

64

01000000

A

65

01000001

B

66

01000010

C

67

01000011

a

97

01100001

b

98

01100010

c

99

01100011

(delete)

127

01111111

 

How does the computer know whether the 01000001 in a byte of memory is the number 65 or the letter A? Because an application program keeps track of what it put where in memory, so MS Word knows that a given byte where it has stored text contains numbers that represent letters.

 

Now that the charts tell stuff it’s now time to look at more charts on how to convert Hexadecimal to base 10, here is the Hexadecimal system of system stuff.

 

Hexadecimal System uses 16 digits:

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

And thus the base is 16.

Hexadecimal numbers are compact and easy to read.
It is very easy to convert numbers from binary system to hexadecimal system and vice-versa, every nibble (4 bits) can be converted to a hexadecimal digit using this table:

 

Decimal
(base 10)

Binary
(base 2)

Hexadecimal
(base 16)

0

0000

0

1

0001

1

2

0010

2

3

0011

3

4

0100

4

5

0101

5

6

0110

6

7

0111

7

8

1000

8

9

1001

9

10

1010

A

11

1011

B

12

1100

C

13

1101

D

14

1110

E

15

1111

F

There is a convention to add “h” in the end of a hexadecimal number, this way we can determine that 5Fh is a hexadecimal number with decimal value of 95.
We also add “0″ (zero) in the beginning of hexadecimal numbers that begin with a letter (A..F), for example 0E120h.

The hexadecimal number 1234h is equal to decimal value of 4660:

If you want to learn how to convert decimals into hexadecimals all u do is divide, here are a lot of charts.

  1. Divide the decimal number by 16.   Treat the division as an integer division.  
  2. Write down the remainder (in hexadecimal).
  3. Divide the result again by 16.  Treat the division as an integer division.  
  4. Repeat step 2 and 3 until result is 0.
  5. The hex value is the digit sequence of the remainders from the last to first.

HEXADECIMAL

0

1

2

3

4

5

6

7

8

9

A

B

C

D

E

F

DECIMAL

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Example 1 
Convert the number 1128 DECIMAL to HEXADECIMAL

NOTES

DIVISION

RESULT

REMAINDER (in HEXADECIMAL)

Start by dividing the number by 16.  

In this case, 1128 divided by 16 is 70.5.  So the integer division result is 70 (throw out anything after the decimal point).

The remainder is (70.5 – 70) multiplied with 16; or (0.5 times 16), which is 8.

1128 / 16

70

8

Then, divide the result again by 16 

(the number 70 on the DIVISION column  comes from the previous RESULT).

In this case, 70/16=4.375.  So the integer division result is 4 (throw out anything after the decimal point)

The remainder is (0.375 multiplied with 16, which is 6.

70 / 16

4

6

Repeat.   Note here that 4/16=0.25.  So the integer division result is 0.

The remainder is (0.25-0) multiplied with 16, which is 4.

4 / 16

0

4

Stop because the result is already 0 (0 divided by 16 will always be 0)

 

 

 

Well, here is the answer. These numbers come from the REMAINDER column values (read from bottom to top)

 

 

468

Side note: You can get the remainder of a division using the Modulus or % operator.  Ie: 1128%16=8.  

Example 2 

Convert the number 256 DECIMAL to HEXADECIMAL

DIVISION

RESULT

REMAINDER (in HEX)

256 / 16

16

0

16 / 16

1

0

1 / 16

0

1

 

 

 

ANSWER

 

100


Example 3
Convert the number 921 DECIMAL to HEXADECIMAL

DIVISION

RESULT

REMAINDER (in HEX)

921 / 16

57

9

57 / 16

3

9

3 / 16

0

3

 

 

 

ANSWER

 

399


Example 4
Convert the number 188 DECIMAL to HEXADECIMAL

DIVISION

RESULT

REMAINDER
(in HEX)

188 / 16

11

C (12 decimal)

11 / 16

0

B (11 decimal)

 

 

 

ANSWER

 

BC

Note that here, the answer would not be 1112, but BC.  Remember to write down the remainder in hex, not decimal.


Example 5
Convert the number 590 DECIMAL to HEXADECIMAL

DIVISION

RESULT

REMAINDER
(HEX)

590 / 16

36

E (14 decimal)

36 / 16

2

4 (4 decimal)

2 / 16

0

2 (2 decimal)

 

 

 

ANSWER

 

24E

Advertisement

Leave a Comment so far
Leave a comment



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s



Follow

Get every new post delivered to your Inbox.