Please enable JavaScript.
Coggle requires JavaScript to display documents.
J276/02 - Section 7 - Data Representation (Binary Numbers (Binary shifts…
J276/02 - Section 7 - Data Representation
Logic
Logic Gates are combined for more complex operations
You can work out the truth tables by working through each gate in order. For every input combination follow them through each gate step-by-step, then write down the output.
The two logic circuits shown above are examples of two-level logic circuits — they require the inputs to pass through a maximum of two logic gates to reach the output.
Multiple logic gates can be added to the same logic circuit to carry out different operations.
Example:
https://drive.google.com/file/d/1-bb44kGvDQ-R3CCnON-_Zjcc892-GE4J/view?usp=sharing
Logic Circuits can have more than two inputs
Example:
https://drive.google.com/file/d/15nZnwMjYvkbxA6pkqOpZTyGLvIsY4_bN/view?usp=sharing
Logic Gates apply boolean operators to inputs
Logic diagrams are often drawn to show logic gates and circuits.
Each type of logic gate is shown by a different symbol.
Each type of logic gate also has a corresponding truth table.
Truth tables show all possible input combinations of 1s and 0s, and the corresponding outputs.
Logic gates are special circuits built into computer chips.
They receive binary data, apply a Boolean operation, then output a binary result.
NOT gate
Take a
single input
and give a
single output.
Output is always opposite the value to the input. If input =
1
, output =
0
. If input =
0
, output =
1
Symbol:
https://drive.google.com/file/d/1N4zI0zH8yBTebnvRD6pLC3CjCAhaPeDX/view?usp=sharing
OR gate
Takes
two inputs
and gives
one output
. If
one or more
inputs = 1, output =
1
,
otherwise
the output is
0
.
Symbol:
https://drive.google.com/file/d/1DI68qvo7dP1cwRTSnq9riaDtqwtWyKHi/view?usp=sharing
AND gate
Takes
two inputs
and gives
one output.
If both inputs = 1, output =
1
,
otherwise
the output is
0
.
Symbol:
https://drive.google.com/file/d/1uIYQi3t24ewVB9yBykd7hmjzpPN6lp1M/view?usp=sharing
Binary Numbers
Overflow errors occur when a number has too many bits
Computers usually deal with these extra bits by
storing
them elsewhere.
Overflow
flags
are used to show that an overflow error has occurred.
Sometimes, during binary arithmetic you will get a result that requires
more
bits than the CPU is expecting - this is called
overflow
.
Example:
https://drive.google.com/file/d/16oGj_LnLR7O9vQm9hTO2GuYYZF93PI-d/view?usp=sharing
Convert denary to binary by subtracting
When converting from
denary
to
binary
, it's easier to
draw a table of binary place values
, then subtract them from
largest
to
smallest
. See the example below...
Example:
https://drive.google.com/file/d/1Lt9k2BsZU5twaIAJY4qBXvh0PrIwbUxT/view?usp=sharing
Binary shifts can be used to multiply or divide by 2
Left shifts MULTIPLY
a binary number.For every place shifted left, the number is
doubled
.
Right shifts DIVIDE
a binary number. For every place shifted right, the number is
halved
.
Gaps at the beginning or end of the number are filled with 0s.
If a number is shifted
3 places right
, it would be
halved three times
(divided by 8). If a number were shifted
4 places left
, it would be
doubled 4 times
(multiplied by 16).
A
binary shift
moves every bit in a binary number left or right a certain number of places.
Left shifts can cause
overflows
(if extra bits are needed), and right shifts cause bits to 'drop off' the end. Bits dropping off or overflowing can lead to a
loss of accuracy/data.
Binary Numbers are easier to convert using tables
Drawing a table
with binary place values in the first row makes binary to denary conversion much easier. See the example below...
Example:
https://drive.google.com/open?id=1v72ckUbc9e0DGtRzmZjvREUdNi8TzM67
Examples of binary shifts
https://drive.google.com/file/d/1Kqe7TXn6f-8JwNK4lpitbZ5-tTVKEl5_/view?usp=sharing
Counting in Binary is a bit like counting in denary
Counting in binary is similar to doing so in denary, but the place values from
right
to
left
increase by
powers of 2
instead of 10.
Binary
only uses
two different digits
(1 and 0) - this is known as
base-2
.
Add binary numbers using column addition
Example:
https://drive.google.com/file/d/1mq-g1YWmU3catqardAXbgquEJub51ePf/view?usp=sharing
As binary only uses 1s and 0s we
can
comfortably do 0+0 = 0, 1+0 = 1 and 0+1 = 1. However, using binary we
can't
write that 1+1 = 2. Instead we
have
to put a 0 and carry a 1. If you get three 1s then put a 1 and carry a 1.
Can lead to overflow errors.
They can be predicted before the binary addition if the total of the binary's denary numbers added together is over 255.
Hexadecimal Numbers
Convert hex to denary by multiplying each character
In hex, moving right to left, place values increase in powers of 16. To convert from
hex to denary
, draw up a table, fill in the boxes, then multiply.
Example:
https://drive.google.com/file/d/1YIpS_8DiKMkB33p37I-vUw16VcgVK06X/view?usp=sharing
Convert binary to hex by splitting it into nibbles
Example:
https://drive.google.com/file/d/1tLH4dZHcQzbah4jz_FqU8d18RdmHg-tA/view?usp=sharing
Each hex character is equal to a
nibble
in binary, so it is possible to convert from binary to hex by splitting the binary code into
4-bit chunks.
Humans struggle with long binary data.
For example, raw pictures use 24 bits per pixel which gives a very large file size.
Hexadecimal numbers are shorter than binary
A single hex character can represent any denary number from 0-15.
Programmers often prefer hex when coding, because:
Due to hex numbers being
shorter
, there's less chance of
input errors.
It's easier to convert between
binary
and
hex
than binary and denary.
It's simpler to remember
large
numbers in hex - they're far shorter than binary numbers.
Hexadecimal
uses sixteen different digits/values.
For hex to binary, use each character's denary value
To convert from
hex
to
binary
, convert each hex character into binary, then just put the binary numbers together.
Example:
https://drive.google.com/file/d/1wlaV8Ol9T0Soos6iPXnm8Eu_lp6lyUoQ/view?usp=sharing
Storing Sound
Sound is Sampled and stored Digitally
Analogue signals need to be converted into digital data so that
computers can read and store sound files. analogue to digital converters
Example:
https://drive.google.com/open?id=1EPTr-qLUX68z3EsJbwhIgK7pyN38WIDM
Sound is recorded by a microphone as an analogue signal.
Analogue signals are pieces of continually changing data.
Several factors affect the Size and Quality of Sound Files
Bit rate = Sampling frequency x sample size
Increasing the sampling frequency means the analogue recording
is sampled more often. The sampled sound will be better quality
and will more closely match the original recording.
Sample size is the number of bits available for each sample (like colour depth but for sound samples).
Increasing the sample size means the digital file picks up quieter sounds, even if they’re happening at the same time as louder ones. This will also result in a sampled sound that is closer to the quality of the original recording.
Sampling frequency (or sample rate) is how many samples you take in a second — it’s usually measured in kilohertz (kHz).E.g. a common sampling frequency is 44,100 samples per second (44.1 kHz).
However, increasing the sampling frequency and sample size will increase the bit rate. This will increase the number of bits in the sound file, which means a larger file size.
Sampling intervals are the gaps between each of the points where the analogue recording is sampled. E.g. the audio file might be sampled every 5 milliseconds (ms) — the sampling interval would be 5 ms.
Compression
Sometimes we need to Compress files
Make file sizes smaller
Compressing data files has many uses
Streaming and downloading files take up less bandwidth
web pages to load more quickly
less storage space
Email services
There are Two Types of compression
Lossless compression makes the file smaller by temporarily removing data to store the file and then restores it to its original state when it’s opened.
Lossy compression works by permanently removing data from the file — this limits the number of bits the file needs and so reduces its size.
Lossy
Pros
Lossy files take up less bandwidth
Commonly used - lots of
software can read lossy files
Greatly reduced file size.
Cons
Lossy compression can’t be used on text
or software files.
Lossy files are worse quality than the
original. This loss in quality is
normally unnoticeable.
Lossy compression loses data — the file
can’t be turned back into the original.
Example of file types
MP3 (audio)
AAC (audio)
JPEG (image)
Lossless
Pros
Lossless files can be decompressed
— turned back into the original.
Lossless compression can be used
on text and software files.
Data is only removed temporarily
so there is no reduction in quality
Cons
Only a slight reduction in file size, so
lossless files still take up quite a bit of space on your device.
Example of file types
FLAC (audio)
TIFF (image)
PNG (image)
Units
Bits are the smallest measure of data
Bit (b)
A single binary digit (1 or 0)
Nibble
4 bits
Byte (B)
8 bits
Kilobyte (KB)
1000 bytes
Megabyte (MB)
1000 kilobytes
Gigabyte (GB)
1000 megabytes
Terabyte (TB)
1000 gigabytes
Petabyte (PB)
1000 terabytes
All the data we want a computer to process must be converted into binary code (1s and 0s). Each 1 or 0 in a binary code is a bit (
b
inary dig
it
).
Parity bits are used to check for errors
If
one bit
of the binary string is
read incorrectly
then the computer will pick up the error.
For binary data, the check digit is called a
parity bit.
You can have
even
and
odd
parity bits.
An
even
parity bit is added to make a binary string have an
even
number of 1s.
An
odd
parity bit is added to make a binary string have an
odd
number of 1s.
If
two bits
within the same binary string are read incorrectly then
no error
will be detected.
Check digits
are a way of checking that data has been
entered
and
read
correctly. They are
digits
added to the
end
of numbers and are calculated using the other digits in the number.
Characters
Binary can be used to represent characters
Computers are unable to process these characters directly as they only process binary code. So they need a way of converting these characters to binary code and vice versa. Done using character sets.
Character sets are collections of characters that a
computer recognises from their binary representation.
As well as the alphanumeric characters mentioned above, character sets also contain special characters which do certain commands (e.g. space, enter and delete).
Alphanumeric characters are used to make words and strings .They include uppercase and lowercase letters, the digits 0-9, and symbols like ? + and £.
When you press a button on your keyboard it sends a binary signal to the computer telling it which key you pressed. The computer then uses the character set to translate the binary code into a particular character.
The number of bits you'll need is based on the character set
ASCII
The most commonly-used character set in the
English-speaking world.Each ASCII character is given a
7-bit binary code.
This means it can represent a total
of 128 different characters.
English alphabet
Numbers
Symbols
Commands
An extra bit (0) is added to the start of the binary code
for each ASCII character (see the table on the right). This means each ASCII character fits nicely into 1 byte.
Example:
https://drive.google.com/file/d/1O22n6D6UEB4vPyHLFURl-mo__d_sp-Xg/view?usp=sharing
Extended ASCII
Character set which gives each character an 8-bit binary
code, allowing for 256 characters to be represented. The first 128 characters are in exactly the same order as the ASCII characters.
Particularly useful for many European languages like French
and German which include accents on some of the vowels, like é, ô and ü.
Different character sets can have different amounts of characters. The number of characters in a character set determines how many bits you’ll need. Here are some standard character sets you should know about:
Unicode®
Comes in several different forms and tries to cover
every possible character that might be written. In its most
common forms it uses 16-bit and 32-bit binary codes.
Covers all major languages, even those that use a completely different alphabet like Greek, Russian and Chinese.
Storing Images
Increasing colour depth and resolution increases file size
Most devices use a 24-bit colour depth, with 8 bits used to indicate the levels of red, green and blue needed for each pixel. It’s estimated that the human eye can see around 10 million different colours, so a 24-bit colour depth should cover every colour that you could possibly see.
The resolution is the density of pixels in an image, i.e. how many pixels are within a certain area. It’s normally measured in dots per inch (dpi)
Total number of colours = 2n (where n = number of bits per pixel, or bpp)
4-bit image: 2^4 = 16 colours
24-bit image: 2^24 = 16 777 216 colours
1-bit image: 2^1 = 2 colours
The higher the resolution, the more pixels in a certain area and so the better quality of image.
The colour depth is the number of bits used for each pixel.
Increasing the resolution or the colour depth means that there are more bits in the image. This improves the image quality, but also increases the file size.
Devices need metadata to display the images
Metadata usually includes the image’s file format, height, width, colour depth and resolution. It can also include extra information, like the time and date that the image was created or last edited.
Without metadata, devices would not be able to display the image on screen as intended.
Metadata is the information stored in an image file which helps the computer recreate the image on screen from the binary data in each pixel.
Images are stored as a series of pixels
Black-and-white images only use two colours,
meaning they only need 1-bit to represent each pixel — 0 for white and 1 for black.
2-bit images can be made up of four colours. Each pixel
can be one of four binary values — 00, 01, 10 and 11.
The colour of each pixel is represented by a binary code number of colours available related to the number of bits the code has.
You can make a greater range of shades and colours by
increasing the number of bits for each pixel.
The type of images you use most often are called bitmap
image they’re mainly used for photos. Bitmap images
are made up of lots of tiny dots, called pixels
Notes from lesson
Binary and Hexadecimal
Binary is used because;
processors use switches
which are on/off. They
conduct a signal
if the signal is on.
Therefore, 1 or 0.
Size
Bit
- 0 or 1
Nibble
- 4 bits
Useful when converting to hex.
Byte
- 8 bits
Character on keyboard.
Kilobyte
- 1000 bytes
Short paragraph of text.
Megabyte
- 1000 kilobytes
Low-resolution images.
Gigabyte
- 1000 megabytes
High-quality videos etc.
Petabyte
- 1000 terabytes
Terabyte
- 1000 gigabytes
Secondary storage capacity.
Possible combinations
As the number of bits increases, the number of possible combinations increases.
For example, 2 bits has 4 combinations, 3 bits has 8 combinations 4 bits has 16 combinations etc.
Formula: Possible combinations = 2^(number of bits)
Binary - Base-2
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
To find the
maximum value of a binary code's length
, use the next bit value
(256) and subtract 1.
Binary shifts
In base 10 (denary) a shift to the left would multiply by 10.
However, in
base 2
(binary) a
shift to the left
would multiply by 2 (
doubles
).
Binary shifts to the right halves it.
Not always accurate as halving sometimes gives a decimal answer.
Text
ASCII
- American Standard Code of Information Language.
Originally only 7-bit code but there aren't enough sequences so it is now 8-bit code.
Every character has a binary value known as a character set.
Every letter has an 8-bit code. ! character = 1 byte
Calculating the size of a text file
: characters x 8 = bits (+10% for file data, known as overheads).
Sound
Sound is analogue
which means it is a
constantly changing
value.
To
digitize sound
means to
sample
and
turn
a sound wave into
numerical data.
Sample points give numerical value
which can be converted into binary.
Advantages of digitizing sound...
Can
email
them.
Easy to
duplicate
.
Easily
portable
.
No deterioration
when replayed.
Can
edit on PC.
Disadvantage of digitizing sound...
Not continuous
- lose quality
Calculating size of a sound file:
sample rate x bit depth x channel x duration
Channels
are either
stereo
(2 channels), or
mono
(1 channel).
2.4 Computational Logic
Boolean Logic - True or false, 1 or 0, on or off.
The transistors used to create 'logic circuits'. Boolean operators are AND, OR and NOT.
For example, IF dark AND movement --> security light on.
IF rains AND no players --> close roof
Truth Tables
Needed to work out the
output
of a
compound statement.
Example: if x == 3
AND
y == 6 print ("They are correct)
Logic Gates
Microprocessors
are
physical
- using
switches
and
transistors
.
AND Logic Gate:
https://drive.google.com/file/d/1uIYQi3t24ewVB9yBykd7hmjzpPN6lp1M/view?usp=sharing
NOT Logic Gate:
https://drive.google.com/file/d/1N4zI0zH8yBTebnvRD6pLC3CjCAhaPeDX/view?usp=sharing
Example: car park barrier, when lifts up, want it to go back down. Need logic gate because don't want barrier to go down if there is a car there. Pressure sensor - if car there, no barrier come down. If car isn't there, make sure barrier is down.
OR Logic Gate:
https://drive.google.com/file/d/1DI68qvo7dP1cwRTSnq9riaDtqwtWyKHi/view?usp=sharing
Images
Resolution is how many pixels there are in an inch.
Bit depth means how many 1s or 0s are stored in
each pixel.
Bit depth
1 bit = 2 colours
2 bits = 4 colours
3 bits = 8 colours
8 bits per pixel = 256 colour combinations
- "True colour"
HOWEVER, most
devices
work at 24 bits per pixel (
RAW
).
Calculating the size of an image file
: width in pixels x height in pixels x bit depth
Compression
Why?
1.8 billion uploads to social media.
Millions - downloaded.
Files being streamed.
Files being sent as attachment.
Storage space available.
Advantages
Less storage space
needed.
Less congestion
on the network.
Less bandwidth
required.
More suited for streaming
(no buffering of large files).
Lossy Compression
Some
data
is
deleted
or
lost
so
never the same as the original.
E.g. 24-bit RAW image is excessive - change to 8 bit for a 256 colour which is class as 'True colour'.
E.g. Sound --> WAV file saves all data but an MP3 file removes high and low frequency data. Usually on average, MP3s are 1/10 file size.
NOT SUITABLE FOR TEXT AS IT REMOVES BITS OF DATA MEANING TEXT WOULD NOT MAKE SENSE.
Lossless Compression
Algorithms use to create a
smaller file.
No data is removed
so is the
same
as the original.
E.g. check for redundant data - words appearing twice.
Text is easy to compress
as there are lots of
repeated
words.
E.g. Run Length Encoding
bit = b
byte = B