Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 38

Binary systems

Unit 1 Data representation

Kibibyte or kilobyte?
• 1 kilobyte is 1000 bytes
• 1 kibibyte is 1024 bytes

• All other unit prefixes work the same way


• 1 megabyte is 1000,000 bytes
• 1 mebibyte is 1,048,576 bytes (1024 x 1024)

Answers must be given in the units specified in the exam question


Binary systems
Unit 1 Data representation

Bits and bytes


• Many units are used for data storage in computers
• 1 bit = a single 0 or 1
• 1 byte = 8 bits = 1 character of text
• 1 nibble = 4 bits or half a byte
• 1 kibibyte = 1024 bytes
• 1 mebibyte = 1024 KiB or 1024x1024 bytes
• 1 gibibyte = 1024 MiB
• 1 tebibyte = 1024 GiB
• 1 pebibyte = 1024 TiB
• 1 exbibyte = 1024 PiB
Binary systems
Unit 1 Data representation

Bits and bytes


• Many units are used for data storage in computers
• 1 bit = a single 0 or 1
• 1 byte = 8 bits = 1 character of text
• 1 nibble = 4 bits or half a byte
• 1 kilobyte = 1000 bytes
• 1 megabyte= 1000 KB or 1000x1000 bytes
• 1 gigabyte = 1000 MB
• 1 terabyte = 1000 GB
Binary systems
Unit 1 Data representation

Numbers with the denary system


Thousands, Hundreds, Tens and Units

1000 100 10 1
2 7 0 3
2x1000 + 7x100 + 0x10 + 3x1 = 2703
Binary systems
Unit 1 Data representation

Binary to Denary

128 64 32 16 8 4 2 1
1 0 0 1 0 1 1 0
Bit values which are one/ 1 , their place values will be added
128+16+4+2 = 150
Binary systems
Unit 1 Data representation

Most and least significant bit


• The most significant bit (MSB) is the bit with the
largest value
• This is the bit that is furthest to the left

• The least significant bit (LSB) is the bit with the


smallest value
• This is the bit that is furthest to the right

128 64 32 16 8 4 2 1
1 0 0 1 1 1 0 1
Binary systems
Unit 1 Data representation

Denary to binary
• How do you convert 28 to binary?
• Method
• Working right to left, write out the numbers 1, 2, 4, 8 and so on, doubling each time to
128

128 64 32 16 8 4 2 1
0 0 0 1 1 1 0 0
• 128, 64 and 32 are all greater than 28, so put a zero for these
• Put a 1 in the 16 column, 28-16=12
• Put a 1 in the 8 column, 12-8 = 4
• Put a 1 in the 4 column, 4-4=0 so put zero in other columns
Hexadecimal
Unit 1 Data representation

Hexadecimal
• Hexadecimal (or hex) is a number system which
uses base 16
• As we only have 10 digits, it uses 0-9 and then the
letters A to F
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 1 2 3 4 5 6 7 8 9 A B C D E F

• What is F in denary? 15
• What is 10 in hex? A
Hexadecimal
Unit 1 Data representation

Hex to denary conversion


• You will only need to translate one- or two-digit hexadecimal numbers

16s Units
2 A
2x16 + 10 = 42 in denary

• Multiply the left-hand digit by 16, then add the units


• What is hex 27 in denary? 2X 16 + 7X1 = 39
Hexadecimal
Unit 1 Data representation

Denary to hex conversion


• Divide the denary number by 16 to get the number of 16s (the left-hand
hex digit)
• The remainder gives you the units
Denary 18 becomes:
18 / 16 = 1 remained 2 so
the hex value for 18 is 12
(Spoken, ‘One Two’, not ‘Twelve’)
• What is denary 27 in hex 27/ 16 = 1 remained 11 = 1B
• What is denary 44 in hex? 44/16 = 2 remained 12 = 2C
Hexadecimal
Unit 1 Data representation

Binary to hex conversion


• Take a binary word of 8 bits
11100101
• Divide into two nibbles of 4 bits
1110 0101
• Convert each nibble into its hex value and rejoin
1 1 1 0 = 14 = E in Hex + 0 1 0 1 = 5 in Hex
So 1 1 1 0 0 1 0 1 = E5 in Hex
Hexadecimal
Unit 1 Data representation

Hex to binary conversion


• What is 3B in hex?
Split the two hex characters
3 = 0011 in binary and B = 1011
So 3B = 0011 1011 in binary

What is hex 21 in binary? 0010 0001


What is hex A5 in binary? 1010 0101
Hexadecimal
Unit 1 Data representation

Binary addition
• Use binary to add two numbers together

1 + 1 = 10?
Simple denary
Hexadecimal

addition
Unit 1 Data representation

Work right to left :

1. Add the Units 1


2. If Over 9, Carry Tens 14
3. Add Tens + 17
= 31
The rules of
Hexadecimal

binary addition
Unit 1 Data representation

Work right to left and apply these simple rules:

1. 0 + 0 = 0 11
2. 0 + 1 = 1 1 1 1 0 14
3. 1 + 0 = 1 + 1 1 0 0 12
4. 1 + 1 = 0 Carry 1
= 1 1 0 1 0 26

Rule 2 or 3
5. 1 + 1 + 1 = 1 Carry 1

Carry Bit
Rule 5
Rule 4

Rule 1
Hexadecimal
Unit 1 Data representation

Adding binary values

11
Carry 1
101 01
+ 1 11
=111 00
Hexadecimal
Unit 1 Data representation

Adding numbers
• Computers work with a fixed number of bits at a time
• This can cause problems
• What problem will arise when adding the following bytes and storing the result in one
byte?

11110000
+10011111
Hexadecimal
Unit 1 Data representation

Overflow error
• When the result of an addition is too large for the number of bits the
computer works with, there will be an overflow error

1 1 1 1
1 1 1 1 0 0 0 0
1 0 0 1 1 1 1 1
+ 1 1 0 0 0 1 1 1 1
9th Bit
Binary shifts and two’s complement
Unit 1 Data representation

Multiplying by 2 ( Binary shift left)


• Look again at how we multiply a binary number by 2

128 64 32 16 8 4 2 1
23 0 0 0 1 0 1 1 1
0 0 1 0 1 1 1 Move bits to the left
46 0 0 1 0 1 1 1 0 Put zero in the least
significant bit
Binary shifts and two’s complement
Unit 1 Data representation

Dividing by 2 ( Binary Shift right)


• We divide by 2 by moving the bits to the right

128 64 32 16 8 4 2 1
90 0 1 0 1 1 0 1 0
0 1 0 1 1 0 1 Move the bits to the right
45 0 0 1 0 1 1 0 1 Put zero in the most
significant bit
Binary shifts and two’s complement
Unit 1 Data representation

Two’s complement
• -15 is represented by the two’s complement:
• 1111 0001

• The two’s complement is calculated as follows:


128 64 32 16 8 4 2 1 Calculating -15
15 0 0 0 0 1 1 1 1 First convert 15 to binary
1 1 1 1 0 0 0 0 Then invert all the bits
-15 1 1 1 1 0 0 0 1 Finally add 1 to the
number

• 8-bits allow numbers between -128 and 127 to be


represented
Binary shifts and two’s complement
Unit 1 Data representation

Two’s complement
• What does the following two’s complement negative
number represent?
1011 0001

128 64 32 16 8 4 2 1
1 0 1 1 0 0 0 1
0 1 0 0 1 1 1 0 Invert the bits
0 1 0 0 1 1 1 1 Add 1

01001111 represents 79, so 10110001 represents -79


Binary shifts and two’s complement
Unit 1 Data representation

Uses and benefits of using hexadecimal

Reasons to use hexadecimal


1 The presentation of binary in hexadecimal is compact, less
number of hexadecimal digit can represent more binary
numbers
2 This leads to less chances of error and better readability

Uses of hexadecimal ( real life examples)


1 Color codes in html / CSS are presented in hexadecimal
#A01100
2 MAC addresses and IP V6 are represented in hexadecimal
3. Memory Dump addresses
ASCII and Unicode
Unit 2 Data representation

The ASCII character set


• ASCII (American Standard Code for Information
Interchange) has become the standard code, used
worldwide
• It was originally developed in the 1960s for representing the
English alphabet
• It encodes 128 characters into 7-bit binary codes

• Characters include numbers 0 to 9, uppercase and


lowercase letters A-Z, a-z, punctuation symbols and
the space character
ASCII and Unicode
Unit 2 Data representation
ASCII and Unicode
Unit 2 Data representation

Using different alphabets/ Unicode Character set


• To represent other characters for different
languages, a new code allowing for many more
characters is needed
• Unicode was developed to use 16 bits 65 536
possible combinations
• The 32 bits version gives 4 294 967 296 (over 4 billion)
possible combinations
ASCII and Unicode
Unit 2 Data representation

Sample rate in this example is


6 per second
ASCII and Unicode
Unit 2 Data representation

Sample Resolution( bit depth


is the number of bits required
to store the highest sound
amplitude

Highest amplitude is 7 in this


example

7 is represent in 3 bits which is


111
ASCII and Unicode
Unit 2 Data representation

File Size calculation of a sound file. Below


is given formula to how to calculate a file
size in bits.

Sample Rate: 6 samples in a


second.

Resolution : 4 bits because the


highest amplitude is 15 and 4 bits
can store a 15

Sample Duration = 3 Seconds

File size= 6 *4 *3

= 72 bits

= 72/ 8

= 9 bytes
ASCII and Unicode
Unit 2 Data representation

Sound file size


File size= sampling rate ( in HZ)x duration of the sample ( in seconds) x
sample resolution ( in bits)
Example
Ray will record 1 min 30 seconds of audio with the following settings:
Resolution: 16-bits
Sampling rate: 10 kHz
Calculate file size in KB
File size= 10 x1000 ( HZ) X 90 ( seconds) x 16 bits
= 14,400,000
= 14,400,000 / 8 bytes
= 18,00, 000/ 1000 KB
= 1800 KB
Sound
Unit 1 Data representation

Impact on digital sound quality , how does it


improve
• Recording quality improves:
• the more frequently we sample the sound
• the more accurately we record the wave height

• Increasing the sampling rate (frequency) means recording more data


points ( more samples)
• Increasing the resolution (bit depth) improves the accuracy of each
data point ( more bits per sample)
Images
Unit 1 Data representation

Image resolution
• Resolution is the number of pixels in the image
• High definition (HD) television uses a resolution of
1920 × 1080 pixels
• The first iPhone had a resolution of 320 × 480 pixels
ASCII and Unicode
Unit 2 Data representation
Images
Unit 1 Data representation

Image Size
20 pixels
File size of image=Resolution x bit Depth

Resolution of image = 20 x20


Colours are 8 = Bit Depth is 3

20 pixels
( check previous slide to how to find colour depth)

File size = 20 x 20 x 3

= 1200 bits

=1200/ 8 bytes

= 150 bytes

8 colours
Images
Unit 1 Data representation

Types of Compression- Lossy and


Lossless
Lossy Lossless

File size is permanently reduced Quality and resolution


remains intact

Original file can't be reduced if it is not Original file can be restored


backed up

Quality of the file / data is reduced File size is not permanently


reduced
Compression
Image Sound /video( MP3/4 ) Text ( lossless)
• A compression algorithm is • A compression algorithm is used • A (compression) algorithm is used e.g
used RLE.
• Discards any unnecessary sounds
• No data is removed in the process
• No data is removed in the using perceptual musical shaping
compression process in such as removing background original file can be restored
lossless compression noise / sounds humans can’t hear • Repeated words (are identified) //
Patterns in the data (are identified)
• An index/dictionary of pixels • Reduces sample size / resolution and are indexed/put into a table and
is created and reducing the sample rates
are replaced with their index and their
• The number of times a pixel • Sound is clipped positions are stored (in the table) and
is repeated in a row is stored the number of times the word/pattern
• The data is permanently removed
• Permanently removes the appears is stored (in the table)
pixels which are not easily
noticed by naked eye
Data storage and compression
Unit 1 Data representation

Benefits of compression
• Compression is often used
for files and data that are
sent via the internet
• Transmission times are
reduced meaning that
downloads happen faster
• Data allowances go further
• Less bandwidth is required
• Less storage space is required
to save files
Data storage and compression
Unit 1 Data representation

Run Length Encoding


• RLE uses frequency/data pairs to encode each run length of the same
coloured pixel
• Assuming 1 = white and black = 0, this run could be encoded as:
1111000000000000

• Using RLE, the row could be represented as 4 ‘1’s and 12 ‘0’s or 4 1 12 0

You might also like