Nat 4/5 Computing Science Lesson 1: Binary Computer Systems Nat 4/5 Computing Science Lesson 1: Binary
Lesson Aims By the end of this lesson: You will be able to: Use binary to represent and store positive integers Represent positive integers in binary using up to 8 Bits Represent negative numbers using binary (Nat 5) Represent real numbers using binary (Nat 5)
The two-state machine Computers and storage devices (hard drives, USB Flash drives, CD ROMs, DVDs) have components that have only two states:- On and off 1 represents on 0 represents off
The Decimal & Binary Systems Nat 4/5 The Decimal & Binary Systems We use the decimal or base 10 system This means we have 10 digits : 0-9 Computers use the binary or base 2 system There are two digits: 0 and 1 Each figure is known as a bit Binary digit
Nat 4/5 Decimal Numbers Lets look at how a decimal number is made up: 173 Hundreds Tens Units 1 7 3
Binary Numbers The column headings for binary are :- 128 64 32 16 8 4 Nat 4/5 Binary Numbers The column headings for binary are :- 128 64 32 16 8 4 2 1
Converting Binary to decimal Nat 4/5 Converting Binary to decimal Lets look at how 173 is stored in binary: 128 64 32 16 8 4 2 1 = 128 + 32 + 8 + 4 + 1 = 173
Steps to convert from Binary to Decimal Nat 4/5 Steps to convert from Binary to Decimal Write the binary column headings 128 64 32 16 8 4 2 1 1 Write the binary number below the headings Add the column headings that have a 1: 64+32+4+2 = 102
Converting Decimal to binary Nat 4/5 Converting Decimal to binary Lets look at how to write the decimal value 145 in binary:- 128 64 32 16 8 4 2 1 = 128 + 16 + 1 = 145
Steps to convert from Decimal to Binary Nat 4/5 Steps to convert from Decimal to Binary Write the binary column headings 128 64 32 16 8 4 2 1 1 Write a 1 below each column heading that you want to use – write a 0 below the others Check that the column with a 1 add to make your decimal number: 128 +16 + 2 = 146
Summary Binary only has two values– 0 & 1 Nat 4/5 Summary Binary only has two values– 0 & 1 A single 0 or 1 is known as a bit Binary Digit The place values in binary start on the right at 1 and double every time going to the left. Complete Worksheet 1
What about negative numbers? Nat 5 What about negative numbers? Integers include:- -123, -89, 0, 45, 109876, etc Positive and negative integers are represented using a system called two’s complement 0 at the start = positive number 1 at the start = a negative number
Two’s complement Write -7 :- +7 using 8 bits 0000 0111 Nat 5 Two’s complement Sign – or + Write -7 :- +7 using 8 bits 0000 0111 Change 1’s and 0’s 1111 1000 Add 1 + 1 So -7 is 1111 1001
Nat 5 Twos complement tasks Questions 1 and 2 on Worksheet 1a
Real numbers Decimal Fractions:- 1/10 1/100 1/1000 …. fraction Nat 5 Real numbers Decimal Fractions:- 1/10 1/100 1/1000 …. fraction 0.1 0.01 0.001 …. decimal Binary Fractions:- ½ ¼ 1/8 …. fraction 0.5 0.25 0.125 …. decimal 0.1 0.01 0.001 …. binary
Real numbers Write 10.5 in binary 8 4 2 1 . 0.5 0.25 0.125 Nat 5 Real numbers Write 10.5 in binary 8 4 2 1 . 0.5 0.25 0.125 1 0 1 0 . 1 0 0 What is this number? 0 1 1 1 . 1 1 0 =7.75
Nat 5 Real numbers task Question 3 on Worksheet 1a
Floating point representation From Maths we know that:- 20.125 = .20125 x 102 Mantissa x Base Exponent In binary :- 20.125 = 10100.001 = .10100001 x 2 101 5 in decimal is 101 in binary
Floating point representation Nat 5 Floating point representation The computer stores the mantissa & exponent of a real number .10100001 x 2 101 Mantissa = 10100001 Exponent = 101
Nat 5 Floating point task Question 4 Worksheet 1a