23
Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Embed Size (px)

Citation preview

Page 1: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Binary (Base 2, b)Octal (Oct, Base 8)Hexadecimal (Hex, Base 16, h, 0x)Decimal (Base 10, d)

OR

Counting for Aliens

Page 2: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Why Binary and Hex?

Computers are essentially dumb machines which can only do operations in base 2. They have many many “switches” in their processors each of which can either be on (1) or off (0). Hence all data that is to be manipulated on a computer must be converted to binary behind the scenes. Hex is just a convenient way to avoid working in straight binary.

Page 3: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Representing numbers in differentbases (back to elementary school math)

We all agree we have 14 dots!

Page 4: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Representing numbers in differentbases (back to elementary school math)

1 group of ten and 4 groups of 1 = 14 base 10

Page 5: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Representing numbers in differentbases (back to elementary school math)

1 group of 8 and 6 groups of one = 16 base 8

Page 6: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Representing numbers in differentbases (back to elementary school math)

1 group of 8 and 1 group of 1 four and 1 group of 2 and 0 groups of ones = 1110 base 2

Page 7: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Binary to Decimal1024 512 256 128 64 32 16 8 4 2 1

1 0 0 1 0

10010 base 2 = 16 + 2 = 18 base 10

Let’s try a game………..

Page 8: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Decimal to Binary (method 1) from askville.amazon.com

I) Find the greatest power of two that's smaller than or equal to your number. Put a 1 in that power's place.II) Subtract that power of two from your number. If the result is 0, go to step IV.III) Let your new number be the difference computed in step II. Go to Step I.IV) Fill in 0's in all positions that you haven't already filled in with 1s.

So, let's do this for a number like 2000 decimal:The greatest power of 2 smaller than 2000 is 1024. So we'll put a 1 in that place:1 _ _ _ _ _ _ _ _ _ _ _2000 - 1024 = 976Greatest power of two less than 976 is 512. Put a 1 in that place:1 1 _ _ _ _ _ _ _ _ _ _976 - 512 = 464Greatest power of two less than 464 is 256. Put a 1 in that place:1 1 1 _ _ _ _ _ _ _ _ _464 - 256 = 208.Greatest power of two less than 208 is 128. Put a 1 in that place:1 1 1 1 _ _ _ _ _ _ _ _208 - 128 = 80Greatest power of two less than 80 is 64. Put a 1 in that place:1 1 1 1 1 _ _ _ _ _ _ _80 - 64 = 16Greatest power of two less than (or equal to) 16 is 16. Put a 1 in that place:1 1 1 1 1 _ 1 _ _ _ _ _16 - 16 = 0Fill in 0s in all remaining spaces:1 1 1 1 1 0 1 0 0 0 0 0So, 2000d = 111110100000b

Page 9: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Decimal to Binary (method 2)Take your decimal number and divide it by 2 continuously.

For example,

100 decimal = ______ in binary

100/2= 50 Remainder 050/2= 25, remainder 025/2-12 remainder 112/2=6, remainder 06/2=3, remainder 03/2=1 remainder 11/2=0 remainder 1

The remainder numbers are the binary and you read upwards

So: 1100100 binary for a decimal of 100.

Page 10: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

What the Heck is Hex

• Base 16 is like Base 10 EXCEPT we need more symbols

• In base 10 we represent all values using 10 symbols {0 1 2 3 4 5 6 7 8 9}

• In base 16 we need 6 more symbols for a total of 16 so we use letters

• The symbols used in base to represent all values are {0,1,2,3,4,5,6,7,8,9,A,B,C,D,F}

Page 11: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Binary to Hex and Hex to Binary• Each Hex digit can be easily converted to 4 binary digits.• Each group of 4 binary digits can be easily converted to hex

0h = 0000b 9h = 1001b1h = 0001b Ah = 1010b2h = 0010b Bh = 1011b3h = 0011b Ch = 1100b4h = 0100b Dh = 1101b5h = 0101b Eh = 1110b6h = 0110b Fh = 1111b7h = 0111b8h = 1000b

i.e. 1 3 B 4 h = 0001 0011 1011 0100 b

Page 12: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

HEXadecimal to Decimal

First off know the digits for Hex0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,FSo 7 base 10 = 7 base 16But 13 base 10 = D base 16And F base 16 = 15 base 10This makes for some weirdness7 + 7 = E

Page 13: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Representing numbers in differentbases (back to elementary school math)

We all agree we have 24 dots!

Page 14: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Representing numbers in differentbases (back to elementary school math)

1 group of 16 and 8 ones = 18 base 16

Page 15: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Representing numbers in differentbases (back to elementary school math)

We all agree we have 30 dots!

Page 16: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Representing numbers in differentbases (back to elementary school math)

1 groups of 16 and 14 ones BUT 14 needs to be represent with a single symbol not two symbols like 1 and 4. So in base 16 we use letters. WeUse A for 10, B for 11, C for 12, D for 13, E for 14, and F for 15.So 30 dots is 1E in base 16.

Page 17: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

HEXadecimal to Decimal

Some serious multiplication can be involved

Determine your powers of 16:1 16256 4096 65536………So 1AF0 base 16 = (1)4096 + (10)256 + (15)16 +

(0)1 = 6896 base 10

Page 18: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

HEXadecimal to Decimal

Method two (use binary to help)

Every Hex digit represent 4 binary digits0h = 0000b 9h = 1001b1h = 0001b Ah = 1010b2h = 0010b Bh = 1011b3h = 0011b Ch = 1100b4h = 0100b Dh = 1101b5h = 0101b Eh = 1110b6h = 0110b Fh = 1111b7h = 0111b8h = 1000b

Page 19: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

HEXadecimal to Decimal

Method two continued (use binary to help)Convert the hex digits to groups of 4 binary digitsThen convert the binary to decimal

1AF0 hex = 0001 1010 1111 0000 base 2Working backwards0+0+0+0+16+32+64+128+0+512+0+2048+4096+0+0+0 = 6896

Page 20: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Decimal to HEXadecimal

Method 1) Divide by 16 and write down remainders

700 base 10 / 16 = 43 Remainder 12 43/16 = 2 Remainder 112/16 = 0 Remainder 2 so 700 decimal = 2BC hex

OR Method 2)

Covert to binary and then group in 4 bits 0010 1011 1100 and convert each to a hex digit 2 B C

Page 21: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

HOMEWORK - Practice examples (convert to base 10 for addition)

1. 777 base 10 = ______ base 22. 11001110 b = _______ d3. 2A9 hex = ______ base 2 = ________ base 104. 10 h + 10 d = _____ h = ______ b5. 1010 b + FF h = _____ d6. 16 h + 32 h = ____ d7. 3D7C h = _________ base 2

Page 22: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

HOMEWORK Part 1

• Write down a method for converting between Octal (base 8) and Decimal and vice versa.

• Write down a method for converting between Octal (base 8) and Binary and vice versa.

• Write down a method for converting between Octal (base 8) and Hex and vice versa.

Page 23: Binary (Base 2, b) Octal (Oct, Base 8) Hexadecimal (Hex, Base 16, h, 0x) Decimal (Base 10, d) OR Counting for Aliens

Delving Deeper…• Checking your answershttp://www.easycalculation.com/decimal-converter.php

• Decimal(fractional) numbers in binaryhttp://cs.furman.edu/digitaldomain/more/ch6/dec_frac_to_bin.htmhttp://mathforum.org/library/drmath/view/56091.html

• Signed binary numbers, addition & subtractionhttp://en.wikipedia.org/wiki/Signed_number_representations

• Multiplying and dividing in base 2http://www.helpwithpcs.com/courses/multiplying-dividing-binary-

numbers.htm