Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lesson Objectives Aims

Similar presentations


Presentation on theme: "Lesson Objectives Aims"— Presentation transcript:

1 Lesson Objectives Aims
Be able to identify and use primitive data types such as Integer, real, character, string and Boolean Represent positive integers in binary Use sign and magnitude or twos compliment to represent negative binary numbers Be able to perform addition and subtraction in binary (integers) Represent positive integers as Hexadecimal Convert integers between Binary, Hex and Denary

2 If you don’t know these by now you:
Primitive data types If you don’t know these by now you: Haven’t done your homework Haven’t been completing programming tasks Can’t program…

3 Create a table with the following headings and fill it in, without using the internet or a book:
Data Type Description Example Integer Real/Float Character String Boolean

4 Binary Quantities The smallest piece of information a computer can understand is a 1 or a 0 This single digit is called a BIT. Obviously, this isn’t too useful on its own. If we group 4 BITS together, we have 16 possible combinations – a NYBBLE

5 1 or 0 = Bit 4 bits = Nybble 8 bits = Byte (most common grouping) 1024 bits = 1 Kilobyte (Kb) (2^10) 1024Kb = 1 Megabyte (Mb) (2^20) 1024Mb = 1 Gigabyte (Gb) (2^30) 1024Gb = 1 Terabyte (Tb) (2^40) 1024Tb = 1 Petabyte (Pb) (2^50) All are powers of 2

6 Denary We count in a number system called Denary It is a BASE 10 number system because… There are 10 digits! 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (if you were wondering)

7 Number systems Think about what happens when we count… Eventually we run out of digits What happens at 9? What REALLY does this mean? What does it tell you about the PLACE each number has?

8 What does the Denary number 1654 mean?
Number systems What does the Denary number 1654 mean? 1654 = 1x x x10 + 4x1 Thousands (x1000) Hundreds (x100) Tens (x10) Units (x1) 1 6 5 4

9 It’s all about the BASE. Geddit? See what I did there?
So now we should understand the following ideas: The BASE of our number system is given by the number of digits we have available The PLACE of a digit denotes its value The place value is determined by multiplying the previous column value by the base of the number system It’s all about the BASE. Geddit? See what I did there?

10 Number systems used in CS
Base Binary 2 Octal 8 Denary 10 Hexadecimal 16

11 Hex, Binary and Denary A useful table…

12 Binary Binary has only 2 digits
128 64 32 16 8 4 2 1 Binary has only 2 digits Which is why we have the place/column values shown above If we take a Byte of data, we can store numbers up to 255 Or 256 different COMBINATIONS of numbers (including zero)

13 Hexadecimal Binary numbers can quickly become long and cumbersome This makes them difficult for us to understand Think about how easy it would be to make an error copying a number such as

14 Hexadecimal allows us to shorten these numbers significantly.
Hexadecimal is base 16 There are 16 digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

15 Each column is now worth 16x the previous:
= 4096* *5 + 16*15 + 1*8 = = 5624 4096 256 16 1 5 F 8

16 Denary (Decimal) to binary
Convert 187 to Binary Write out your table (just keep doubling each number from 1) Working from LEFT to RIGHT, put a 1 under each number that is nearest to your remaining total 187 – 128 = 59 59 – 32 = 27 27 – 16 = 11 11 – 8 = 3 3 – 2 = 1 1-1 = 0 187 = 128 64 32 16 8 4 2 1

17 Denary (Decimal) to Hex
First convert to Binary 187 = Then split in to two Nybbles Convert Nybbles to Hex 1011 = 11 = B in Hex 187 = BB 128 64 32 16 8 4 2 1

18 Hex to Binary Take each hex digit F8 Turn each in to a 4 bit Nybble F = 1111, 8 = 1000 Combine:

19 Hex to Decimal (Denary)
Convert to Binary first! Then convert from Binary to Decimal F8 = = = 248

20 Addition and Subtraction
Addition is eeeeeaasssssyyyyy Repeat after me: Which truth table is this…? Sum Equals 0 + 0 0 + 1 1 1 + 0 1 + 1 0… er?

21 Now do some sums.. Sum Equals 0 + 0 0 + 1 1 1 + 0 1 + 1 0 CARRY 1 1 CARRY 1 + + +

22 Subtraction Sum Equals 0 - 0 1 - 0 1 1 - 1 0 – 1 = 10 - 1
1 - 0 1 1 - 1 0 – 1 = 01 (borrowing from the next column IF it’s 1) 0 – 1 if the column next doesn’t contain a 1?! PANIC!!!! 11 – 1

23 Worked Examples 1 – 1 = 0 0 – 0 = 0 1 – 0 = 1 Answer - 1000 - 1011
0011 1 – 1 = 0 0 – 0 = 0 1 – 0 = 1 Answer

24 10 - 5 1010 - 0101 1010 0101 ----

25 10 - 7 1010 - 0111 1 0000 0111 ---- 1 11 0000 0111 ---- 1 11 0000 0111 ---- 0011

26 - - - -

27 But… what about negative numbers??
There has to be a way? Yes, but it’s a compromise which reduces the maximum size of a number that can be stored in a byte.

28 The simplest system is sign and magnitude Normal binary number (150):
128 64 32 16 8 4 2 1 Sign Magnitude 64 32 16 8 4 2 1

29 Magnitude = the size of the actual number
Sign bit = 0 or 1 1 = negative 0 = positive Magnitude = the size of the actual number

30 Two’s Compliment Sets the sign bit to be negative (like in sign and magnitude) But it’s not a flag – it means the negative value of its column So in 8 bit numbers, -128

31 Two’s compliment conversion
To represent the number -13 as an 8-bit binary number... Step 1 : Convert the positive number 13 into an 8-bit binary integer: 128 64 32 16 8 4 2 1 Step 2 : Change all the bits from 0 to 1 (or from 1 to 0.) 128 64 32 16 8 4 2 1 Step 3 : Add 1 - Perform a binary calculation. 1 +

32 The column values are now slightly different.
What negative number is this? Flip the bits and add 1! Or - 128 64 32 16 8 4 2 1

33 Subtraction with 2’s compliment
10 – 4… 10 = = Convert the number to subtract (4) in to two’s compliment: Now add… The 1 has overflowed (consider it dead…) what’s left is the correct answer.

34 Lesson Objectives Aims Key Words
I. Perform bitwise manipulation and use masks with AND, OR and XOR J. Understand the use of character sets (ASCII and Unicode) to represent text Key Words

35 Processors will have the ability to perform “shift” operations
Logical Operators Processors will have the ability to perform “shift” operations There are two types: Logical Arithmetic They both have similar effects but are subtly different

36 Why - Quick arithmetic! Shifting bits RIGHT will DIVIDE the number by 2 Shifting bits LEFT will MULTIPLY the number by 2

37

38

39 Operators You MUST be already familiar with: NOT AND OR XOR

40 Not – inverse, 1’s compliment AND – Find the status of a bit
OR – Reset/Change values XOR – find matching bits Any byte/register size operations with these are called “masks” or “bitwise manipulation” E.g. AND (mask)

41 ASCII – 127 characters (8 bits, 1 parity) Unicode – 16 bits, now more
ASCII and Unicode ASCII – 127 characters (8 bits, 1 parity) Unicode – 16 bits, now more Enables all languages to be stored World wide standard Should display on any device/OS/Compliant software

42 Review/Success Criteria


Download ppt "Lesson Objectives Aims"

Similar presentations


Ads by Google