Download presentation
Presentation is loading. Please wait.
1
Fundamentals of Data Representation
Number Systems and Binary
2
Fundamentals of Data Representation: Number Systems and Binary
“There are 10 types of people in the world: Those who understand binary, and those who don’t.” Do you understand the saying? Fundamentals of Data Representation: Number Systems and Binary
3
Number Systems (Denary)
As far as numbers go, we’re most used to denary It’s the number system that uses 10 possible digits 0 to 9 A number is made up of as many of these digits as needed 1 34 Fundamentals of Data Representation: Number Systems and Binary
4
Number Systems (Denary)
Digits are valued from greatest to least As we read them from left to right Take the number 351 The value increases from right-to-left Adding more digits to the left makes ‘ten-thousands’, ‘hundred- thousands’, and so on 351 3 Hundreds 5 Tens 1 Ones Fundamentals of Data Representation: Number Systems and Binary
5
Number Systems (Denary)
We can think of it this way For any number The most significant side is the left The least significant side is the right Changing the most significant digit Makes a big change on the number Changing the least significant digit Makes a small change on the number 351 3 Most Significant 5 1 Least Significant Fundamentals of Data Representation: Number Systems and Binary
6
Number Systems (Denary)
There are all kinds of numbers in the denary system /54 There are categories (called sets) for these numbers Some sets contain others Rational contains Integer, which contains Natural Real contains Rational and Irrational Set Symbol Examples Natural ℕ 0, 1, 2, 3, … Integer ℤ …, -3, -2, -1, 0, 1, 2, 3, … Rational ℚ Any fractional number (1/2, 7/1, 13/231) Irrational n/a Any non-fractional number (√2, 𝜋) Real ℝ All possible numbers (Natural, Integer, Rational, and Irrational) ℕ⊂ℤ⊂ℚ ℚ⊂ℝ ⊂ means “subset” (any number on the left is also in the right) Fundamentals of Data Representation: Number Systems and Binary
7
Fundamentals of Data Representation: Number Systems and Binary
State what the smallest set each of the numbers belongs to I.e. for 3, say Naturals rather than Integers. 100 0.4 𝝅 10/20 -3 √𝟓 20/2 -10.2 ANSWERS From top-left to bottom-right: Naturals Rationals Irrationals Rationals Integers Irrationals Naturals Rationals Naturals Fundamentals of Data Representation: Number Systems and Binary
8
Number Bases Every number system works off a base Denary is in base 10
That means every digit has 10 possible values 0 to 9 Base 9 would have 9 possible values 0 to 8 Base 4 would have 4 possible values 0 to 3 The base appears near the bottom of the number 35110 0.510 Fundamentals of Data Representation: Number Systems and Binary
9
Fundamentals of Data Representation: Number Systems and Binary
Number Bases With any base, we can calculate the denary result Each next significant digit is always the next power up of the base E.g. the least significant digit is always [base]0 Then we have [base]1 We multiply the digit’s worth by the digit Finally, we add together each product to get the final result (3 x 102) + (5 x 101) + (1 x 100) = (3 x 100) + (5 x 10) + (1 x 1) = = 351 Fundamentals of Data Representation: Number Systems and Binary
10
Fundamentals of Data Representation: Number Systems and Binary
Number Bases Calculating this result is a bit redundant in denary We already have the result But this lets us convert other number systems to denary Let’s look at another number system Called binary Fundamentals of Data Representation: Number Systems and Binary
11
Number System (Binary)
The binary number system is a base 2 system Has 0 and 1 as possible digits Here are some examples Still follows the same number system rules Digit on right is least significant Digit on left is most significant Each digit is worth [base]n, where n is digit’s place (from the right) As its base 2, each next digit is worth twice as much 00101 101 1101 1 01010 Fundamentals of Data Representation: Number Systems and Binary
12
Number System (Binary)
Let’s look at a number The number in binary is 1001 Can also be written as 10012 Let’s readers know its in base 2 Can calculate its denary value by doing the calculation from before Multiply the digit’s worth by the digit’s value (23 x 1) + (22 x 0) + (21 x 0) + (20 x 1) = (8 x 1) + (4 x 0) + (2 x 0) + (1 x 1) = = 9 Fundamentals of Data Representation: Number Systems and Binary
13
Fundamentals of Data Representation: Number Systems and Binary
Calculate the denary value for each of these binary numbers 1101 0010 0101 010101 001100 100000 ANSWERS From top-left to bottom-right: 13 2 5 Fundamentals of Data Representation: Number Systems and Binary
14
Number System (Binary)
Binary numbers always have a maximum value Based on number of digits in the number The maximum value is when all digits in the binary number are 1 Here are some examples 2 digits: 3 3 digits: 7 4 digits: 15 There is a simple calculation for it 𝑚𝑎𝑥𝑉𝑎𝑙𝑢𝑒= 2 𝑛 −1 Where 𝑛 is the number of digits Fundamentals of Data Representation: Number Systems and Binary
15
Fundamentals of Data Representation: Number Systems and Binary
What is the maximum value for binary numbers with the following amount of digits? 5 6 7 8 9 10 ANSWERS From top-left to bottom-right: 31 63 Fundamentals of Data Representation: Number Systems and Binary
16
Fundamentals of Data Representation: Number Systems and Binary
Denary to Binary Turning a number from one system into another is an example of conversion The exercise made you convert from binary to denary How about going the other way around? It’s not as simple But still easy to follow Fundamentals of Data Representation: Number Systems and Binary
17
Fundamentals of Data Representation: Number Systems and Binary
Denary to Binary We start with a number Then we find the largest power of 2 that fits in it Cannot be larger We take this power away from the number Ending up with a result We put a 1 in that digit on the binary number We put 0 if we can’t subtract it We repeat this process, going down the powers Until we reach the end The end result is the binary version Starting number: 103 Largest Power of 2: 64 (26) Take the power away: – 64 = 59 Mark that as a 1: > 1 Then look at next power: 32 (25) Take that power away: 59 – 32 = 27 Marks that as a 1: > 1 And repeat the process… 27 – 16 = 11 24 -> 1 11 – 8 = 3 23 -> 1 3 – 4 (CAN’T DO) 22 -> 0 3 – 2 = 1 21 -> 1 1 – 1 = 0 20 -> 1 End up with Fundamentals of Data Representation: Number Systems and Binary
18
Fundamentals of Data Representation: Number Systems and Binary
Calculate the binary value for each of these denary numbers 15 7 3 78 64 80 125 200 255 ANSWERS From top-left to bottom-right: Fundamentals of Data Representation: Number Systems and Binary
19
Fundamentals of Data Representation: Number Systems and Binary
Binary in Computers There’s a reason why binary is important It’s used on computers every day Computers are made up of electrical circuits These circuits have two states: low voltage, and high voltage Seem familiar? If there are only two states, we can represent a circuit using a single binary digit Low voltage: 0 High voltage: 1 Fundamentals of Data Representation: Number Systems and Binary
20
Fundamentals of Data Representation: Number Systems and Binary
Binary in Computers These voltages (and subsequent binary) are used for lots of things Data on computers Images Numbers Characters Video Memory addresses Where things are stored on a computer Using binary to store data (like text) is known as encoding Something we’ll be looking at this term Fundamentals of Data Representation: Number Systems and Binary
21
Fundamentals of Data Representation: Number Systems and Binary
Binary in Computers Data on a computer has a very specific unit Bits Each digit in a binary number is a single bit So, a 4 digit binary number has 4 bits A group of 8 bits makes a single byte Either 32 or 64 bits (depending on the computer architecture) makes a word Bit: 0 or 1 (single digit) Byte: (8 bits) Word: 32/64 bits (depending on computer architecture) Fundamentals of Data Representation: Number Systems and Binary
22
Fundamentals of Data Representation: Number Systems and Binary
Units of Data Things on the computer can get pretty large Videos, for example, are typically larger than text documents Showing their size in bytes would end up with very large numbers Instead, we can use other units of measurement There are two types for data Units representing powers of 2: kibibytes Units representing powers of 10: kilobytes Fundamentals of Data Representation: Number Systems and Binary
23
Fundamentals of Data Representation: Number Systems and Binary
Units of Data In SI (International System of Units), we have base units Metres (m) Litres (l) Bytes (B) We can represent larger values by adding prefixes kilo (103) kilometres (km) kilolitres (kl) kilobytes (kB) mega (106) megametres (Mm) megalitres (Ml) megabytes (MB) giga (109) gigametres (Gm) gigalitres (Gl) gigabytes (GB) tera (1012) terametres (Tm) teralitres (Tl) terabytes (TB) Fundamentals of Data Representation: Number Systems and Binary
24
Fundamentals of Data Representation: Number Systems and Binary
Units of Data So, we have 1kB = 1,000B 1MB = 1,000kB = 1,000,000B 1GB = 1,000MB = 1,000,000kB = 1,000,000,000B 1TB = 1,000GB = 1,000,000MB = 1,000,000,000kB = 1,000,000,000,000B However, binary works in base 2, not base 10 So there’s a different set of units we can use Fundamentals of Data Representation: Number Systems and Binary
25
Fundamentals of Data Representation: Number Systems and Binary
Units of Data We can use the ‘kibi’ equivalent of the prefixes kibibyte: KiB 1KiB = 210B = 1,024B mebibyte: MiB 1MiB = 210KiB = 220B = 1,048,576B gibibyte: GiB 1GiB = 210MiB = 220KiB = 230B = 1,073,741,824 tebibyte: TiB 1TiB = 210GiB = 220MiB = 230KiB = 240B = 1,099,511,627,776B These are more ‘accurate’ than the SI units, as these units work in base 2 Historically, kilo has been used when kibi was actually meant In terms of hard-drive sizes Fundamentals of Data Representation: Number Systems and Binary
26
Fundamentals of Data Representation: Number Systems and Binary
Binary Arithmetic Like denary numbers, we can add, subtract, multiply, and divide binary numbers We’ll look at addition, subtraction, and multiplication Division is tricky, and not needed for the A Level We’ll start simple with addition It works exactly like adding denary numbers We work from the least to the most significant digits, and add the digits on the same column If we have an overflow (i.e. add up to make a two-digit number) we carry it over to the next column Fundamentals of Data Representation: Number Systems and Binary
27
Binary Arithmetic (Addition)
Here’s an example Here we’re adding to 00110 We work our way, from the right to the left, adding the digits Any time there’s too much we carry it over to the next digit Essentially, long addition! 1 + = Carries Fundamentals of Data Representation: Number Systems and Binary
28
Binary Arithmetic (Addition)
We can always check our work afterwards Convert binary numbers to denary Including our answer Add up denary numbers See if the two answers match 1 + = Carries → 1110 → 610 = 17 → 1710 Same answer, therefore we are correct! Fundamentals of Data Representation: Number Systems and Binary
29
Fundamentals of Data Representation: Number Systems and Binary
Add the following binary numbers Show the answer in binary as well ANSWERS From top-left to bottom-right: Fundamentals of Data Representation: Number Systems and Binary
30
Binary Arithmetic (Multiplication)
Binary multiplication follows the same steps as denary multiplication We’ll use long multiplication Write the two numbers, one above the other Then multiply each digit on one number with each digit on the other Write them as separate numbers Shifting up a significant digit every time Finally, add numbers together 1 x + Fundamentals of Data Representation: Number Systems and Binary
31
Fundamentals of Data Representation: Number Systems and Binary
Multiply the following binary numbers Show the answer in binary as well 101 𝐱 10 111 𝐱 101 11 𝐱 111 ANSWERS From top-left to bottom-right: Fundamentals of Data Representation: Number Systems and Binary
32
Signed Binary (Two’s Complement)
Every binary number we’ve dealt with has been unsigned Take this number: 42 We already know its positive Now take this number: -42 The only way we know its negative is because of the minus sign If that wasn’t there, we could mistake it for positive Numbers on a computer are stored in bits Binary digits We need to store this minus sign as well We haven’t done that so far Fundamentals of Data Representation: Number Systems and Binary
33
Signed Binary (Two’s Complement)
In a signed binary system, we use one bit for the sign 0 is for positive 1 is for negative There are lots of signed systems for binary numbers We’re using one Two’s Complement 0110 0010 0000 1000 0100 1100 1010 1110 1011 1001 1101 1111 0101 0111 0011 0001 – + +6 +2 +4 +5 +7 +3 +1 -8 -4 -6 -2 -5 -7 -3 -1 Fundamentals of Data Representation: Number Systems and Binary
34
Signed Binary (Two’s Complement)
In this system, each digit is still a power of 2 However, the most significant digit is now negative In 4 bit number, most significant = -8 In 5 bit number, most significant = -16 In 6 bit number, most significant = -32 We calculate denary of binary number in same way as before Multiply digits by digit’s value Add results together 0110 0010 0000 1000 0100 1100 1010 1110 1011 1001 1101 1111 0101 0111 0011 0001 – + +6 +2 +4 +5 +7 +3 +1 -8 -4 -6 -2 -5 -7 -3 -1 Fundamentals of Data Representation: Number Systems and Binary
35
Signed Binary (Two’s Complement)
Here’s an example of some signed binary numbers We can still have positive numbers in this system 0110 0010 0000 1000 0100 1100 1010 1110 1011 1001 1101 1111 0101 0111 0011 0001 – + +6 +2 +4 +5 +7 +3 +1 -8 -4 -6 -2 -5 -7 -3 -1 -8 4 2 1 Denary 3 -4 -1 Fundamentals of Data Representation: Number Systems and Binary
36
Denary to Two’s Complement
Converting any denary number into Two’s Complement is easy First convert to unsigned binary If the number is negative, then Flip all the bits (0’s to 1’s, and 1’s to 0’s) Add 1 to least significant bit Negative Example Denary Number: -4 1) Unsigned Binary: 100 2) Two’s Compliment: 0100 Still add 0 as we haven’t added the minus sign yet 3) Flipped Bits: 4) Add 1 to LSB: 1100 Positive Example Denary Number: 4 1) Unsigned Binary: 100 2) Two’s Compliment: 0100 Added 0 to show that number is positive Fundamentals of Data Representation: Number Systems and Binary
37
Fundamentals of Data Representation: Number Systems and Binary
Convert the following denary numbers into Two’s Complement signed binary numbers -8 -7 -3 -14 -10 -1 ANSWERS From top-left to bottom-right: Fundamentals of Data Representation: Number Systems and Binary
38
Two’s Complement to Denary
We have two methods for converting Two’s Complement binary numbers to denary Method 1: Multiply digits by their worth, and add together Method 2 (only needed if negative): Flip bits, add 1, and then use Method 1 Method 1 Two’s Compliment: 1) Find values: (32 x 0) + (16 x 1) + (8 x 1) + (4 x 0) + (2 x 1) + (1 x 0) 2) Sum values: = 26 Method 2 Two’s Compliment: negative number, so we use Method 2 1) Flip bits: 2) Add 1 to LSB: 3) Find values: (32 x 0) + (16 x 0) + (8 x 0) + (4 x 1) + (2 x 1) + (1 x 0) 4) Sum values: = 6 5) Add sign: -6 needed as binary number was negative Fundamentals of Data Representation: Number Systems and Binary
39
Fundamentals of Data Representation: Number Systems and Binary
Convert the following Two’s Complement signed binary numbers to denary 1100 0101 1001 010011 110011 111111 ANSWERS From top-left to bottom-right: Fundamentals of Data Representation: Number Systems and Binary
40
Two’s Complement Arithmetic
Arithmetic follows the same steps in Two’s Complement However, rather than subtracting numbers, we can add negative ones! Example We have: – (9 – 6) Can change this to: (-00110) So we flip the bits: (-11001) Then add 1 to LSB: now have a negative number Then we add them: 01001 … we ignore the final carry in this sum otherwise carry goes on forever This gives us: Converted to denary: 3 Fundamentals of Data Representation: Number Systems and Binary
41
Fundamentals of Data Representation: Number Systems and Binary
For the following denary operations, convert them to Two’s Complement and then perform the operation For any subtractions, use a negative addition instead Show the answer in Two’s Complement binary 12 + 6 5 – 2 0 - 10 16 - 0 ANSWERS From top-left to bottom-right: Fundamentals of Data Representation: Number Systems and Binary
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.