Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Representation – numbers Binary conversion Hexadecimal Negative numbers Binary addition Binary shifts.

Similar presentations


Presentation on theme: "Data Representation – numbers Binary conversion Hexadecimal Negative numbers Binary addition Binary shifts."— Presentation transcript:

1 Data Representation – numbers Binary conversion Hexadecimal Negative numbers Binary addition Binary shifts

2 Basic Binary 1 = switch closed / electricity on 0 = switch open / electricity off If you send 1 bit, how many different combinations can you send? 1 or 0 If you send 2 bits, how many different combinations can you sent? bits? 4 bits? 5 bits?

3 Terminology Bit 1 or 0 Nibble 4 bits Byte 2 nibbles / 8 bits KB
Kilobyte 1000/1024 bytes MB Megabyte 1000/1024 KB GB Gigabyte 1000/1024 MB TB Terabyte 1000/1024 GB

4 Binary - Decimal 128 64 32 16 8 4 2 1 8 1 = 9 128 64 32 16 8 4 2 1 128 32 4 2 = 166

5 Have a go 1 2 3 128 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1 Answers: 1 = 49, 2 = 154, 3 = 247, 4 = 158, 5 = 249, 6 = 741, 7 = 1543, 8 = 2405, 9 = 62423, 10 = 34582

6 Patterns If the least significant bit (right most) is a 1, the number is odd All 1s = the next number -1 e.g. = 127 The smallest number in positive binary is always 0 The number of combinations is equal to the next number = 128 different combinations 0 to 127 128 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1

7 Decimal - Binary 23 23 – 16 = 7 7 – 4 = 3 128 64 32 16 8 4 2 1 98 98 – 64 = 34 34 – 32 = 2 128 64 32 16 8 4 2 1 242 242 – 128 = 114 114 – 64 = 50 50 – 32 = 18 18 – 16 = 2 128 64 32 16 8 4 2 1

8 Have a go 28 43 78 101 200 Answers: 1 = 11100, 2 = , 3 = , 4 = , 5 = , 6 = , 7 = , 8 = , 9 = , 10 =

9 Hexadecimal Easier to remember than binary
1 nibble can be: Decimal Hexadecimal 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 A 11 B 12 C 13 D 14 E 15 F Hexadecimal Easier to remember than binary Quicker/easier to write than binary Can be converted quickly to binary (and back) Each nibble is converted into a single hexadecimal number

10 Hexadecimal - binary 3A 3 A 0011 1010 00111010 F20 F 2 0

11 Have a go, hex-bin 11 2A BB 6C A0 50F 9BD D5AA 1974 26ABEB
Answers: 1 = , 2 = , 3 = , 4 = , 5 = , 6 = , 7 = , 8 = , 9 = , 10 =

12 Binary - Hexadecimal E F5B

13 Have a go, binary-hex Answers: 1 = 6A, 2 = BF, 3 = 80, 4 = 5F, 5 = E6B, 6 = 2AC, 7 = F0F, 8 = 33F, 9 = 5E2B, 10 = FF16

14 Hexadecimal - Decimal Convert to binary and then to decimal… Or… 161
160 3 A 3A = Convert to binary and then to decimal… Or… (3 * 16) + (10 * 1) = 58 162 161 160 162 161 160 1 D 3 1D3 = 256 16 1 (1 * 16 * 16 ) + (13 * 16) + (3 * 1) = 467

15 Have a go, hex-dec 11 2A BB 6C A0 50F 9BD D5AA 1974 26ABEB
Answers: 1 = 17, 2 = 42, 3 = 187, 4 = 108, 5 = 160, 6 = 1295, 7 = 2493, 8 = 54698, 9 = 6516, 10 =

16 Decimal – Hexadecimal 78 = 4E 199 = C7
299 = 12B 256 16 1 4 14 Convert the binary and then hexa Or 256 16 1 12 7 162 161 160 256 16 1 2 11

17 Have a go – dec-hex 22 59 100 189 231 257 1056 2000 3578 32444 Answers: 1 = 16, 2 = 3B, 3 = 64, 4 = BD, 5 = E7, 6 = 101, 7 = 420, 8 = 7D0, 9 = DFA, 10 = 7EBC

18 Binary Addition What is 1 + 1? What is 0 + 0? What is 1 + 1 + 1?
What is 1 + 1? 1 What is 0 + 1? 1 What is ? 1

19 Binary addition – 4 basic rules
1 0 + 0 = = = 0 carry = 1 carry 1 1

20 1 1 Overflow = the result of the addition is too large to fit in 8 bits. A 9th bit is needed to store the result. (1)

21 Have a go, binary addition
1 1 1 (1) 1 (1) 1 If adding 4 1s, the result is binary , put a 0 in the box carry the 1 across two columns to the left 1 (1) (1)

22 Negative numbers – Sign and Magnitude
The MSB bit (left most) gives the sign (it does not have a numeric value). 1 = negative, 0 = positive 0011 = = = = -10 Work out the binary – add a 0 or a 1 at the front

23 Have a go, dec – sign and mag
22 -33 59 -100 105 -106 -221 398 -512 -1069 Answers: 1 = , 2 = , 3 = , 4 = , 5 = , 6 = , 7 = , 8 = , 9 = , 10 =

24 Negative numbers – Two’s complement Dec – two’s
Convert the number to binary as normal. Make sure there is a 0 in the MSB. If the decimal number is positive, you already have the answer. If it is negative, you need to flip it: Method 2: Right to left write down all the bits up to and including the first 1. Flip the rest Keep same: Flip the rest: Method 1: 1. Flip all the bits 2. Add Flip: Add 1:

25 Dec-two’s examples 59 Convert to binary (with a 0 at the front): is positive, so the answer is Convert to binary (with a 0 at the front): Flip all the bits: Add 1:

26 Have a go, Dec – two’s 22 -33 59 -100 105 -106 -221 398 -512 -1069
Answers: 1 = , 2 = , 3 = , 4 = , 5 = , 6 = , 7 = , 8 = , 9 = , 10 =

27 Two’s complement, two’s-dec
Check the first bit. If it is a 0 – convert it to decimal as normal. If it is a 1, you need to flip it, then work it out as normal: Method 1: 1. Flip all the bits 2. Add 1 Flip: Add 1: Method 2: Right to left write down all the bits up to and including the first 1. Flip the rest Keep same: Flip the rest:

28 Two’s-dec examples First bit = 0 so convert as normal = First bit = 1 so flip and add 1 Flip: Add 1: Convert: -108

29 Have a go, Two’s – dec Answers: 1 = 53, 2 = -70, 3 = -64, 4 = 70, 5 = 85, 6 = -86, 7 = -166, 8 = -114, 9 = 3413, 10 = -5419

30 Binary Shifts Move binary numbers a set number of places to the left, or the right Logical shift – spaces are filled in with 0s Arithmetic shift – when shifting left the spaces are filled with 0s, when shifting right they are filled with the MSB

31 Logical 1 Left shift 2 spaces 1 1 Right shift 2 spaces 1

32 Arithmetic 1 Left shift 2 spaces 1 1 Right shift 2 spaces 1

33 What do they do? Each left shift (log/ari) multiplies the number by 2
Each logical right shift divides the number by 2 Each arithmetic right shift divides the number by 2 but keeps the sign (positive/negative for two’s complement) (Arithmetic left shift will keep the sign if bits are not removed)

34 Have a go, shifts Type Left/Right Num Places Binary 1 Logical Left
2 Arithmetic 3 Right 4 5 6 7 8 9 10 Answers


Download ppt "Data Representation – numbers Binary conversion Hexadecimal Negative numbers Binary addition Binary shifts."

Similar presentations


Ads by Google