J276/02 - Section 7 - Data Representation (Binary Numbers (Binary shifts…
J276/02 - Section 7 - Data Representation
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.
Logic Circuits can have more than two inputs
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.
and give a
Output is always opposite the value to the input. If input =
, output =
. If input =
, output =
one or more
inputs = 1, output =
the output is
If both inputs = 1, output =
the output is
Overflow errors occur when a number has too many bits
Computers usually deal with these extra bits by
are used to show that an overflow error has occurred.
Sometimes, during binary arithmetic you will get a result that requires
bits than the CPU is expecting - this is called
Convert denary to binary by subtracting
When converting from
, it's easier to
draw a table of binary place values
, then subtract them from
. See the example below...
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
Right shifts DIVIDE
a binary number. For every place shifted right, the number is
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).
moves every bit in a binary number left or right a certain number of places.
Left shifts can cause
(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...
Examples of binary shifts
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
powers of 2
instead of 10.
two different digits
(1 and 0) - this is known as
Add binary numbers using column addition
As binary only uses 1s and 0s we
comfortably do 0+0 = 0, 1+0 = 1 and 0+1 = 1. However, using binary we
write that 1+1 = 2. Instead we
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.
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.
Convert binary to hex by splitting it into nibbles
Each hex character is equal to a
in binary, so it is possible to convert from binary to hex by splitting the binary code into
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
, there's less chance of
It's easier to convert between
than binary and denary.
It's simpler to remember
numbers in hex - they're far shorter than binary numbers.
uses sixteen different digits/values.
For hex to binary, use each character's denary value
To convert from
, convert each hex character into binary, then just put the binary numbers together.
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
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.
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
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 files take up less bandwidth
Commonly used - lots of
software can read lossy files
Greatly reduced file size.
Lossy compression can’t be used on text
or software files.
Lossy files are worse quality than the
original. This loss in quality is
Lossy compression loses data — the file
can’t be turned back into the original.
Example of file types
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
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
Bits are the smallest measure of data
A single binary digit (1 or 0)
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 (
Parity bits are used to check for errors
of the binary string is
then the computer will pick up the error.
For binary data, the check digit is called a
You can have
parity bit is added to make a binary string have an
number of 1s.
parity bit is added to make a binary string have an
number of 1s.
within the same binary string are read incorrectly then
will be detected.
are a way of checking that data has been
correctly. They are
added to the
of numbers and are calculated using the other digits in the number.
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
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.
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.
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:
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.
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.
- 0 or 1
- 4 bits
Useful when converting to hex.
- 8 bits
Character on keyboard.
- 1000 bytes
Short paragraph of text.
- 1000 kilobytes
- 1000 megabytes
High-quality videos etc.
- 1000 terabytes
- 1000 gigabytes
Secondary storage capacity.
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.
In base 10 (denary) a shift to the left would multiply by 10.
shift to the left
would multiply by 2 (
Binary shifts to the right halves it.
Not always accurate as halving sometimes gives a decimal answer.
1.8 billion uploads to social media.
Millions - downloaded.
Files being streamed.
Files being sent as attachment.
Storage space available.
Less storage space
on the network.
More suited for streaming
(no buffering of large files).
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.
Algorithms use to create a
No data is removed
so is the
as the original.
E.g. check for redundant data - words appearing twice.
Text is easy to compress
as there are lots of
E.g. Run Length Encoding
Sound is analogue
which means it is a
a sound wave into
Sample points give numerical value
which can be converted into binary.
Advantages of digitizing sound...
edit on PC.
Disadvantage of digitizing sound...
- lose quality
Calculating size of a sound file:
sample rate x bit depth x channel x duration
(2 channels), or
Resolution is how many pixels there are in an inch.
Bit depth means how many 1s or 0s are stored in
1 bit = 2 colours
2 bits = 4 colours
3 bits = 8 colours
8 bits per pixel = 256 colour combinations
- "True colour"
work at 24 bits per pixel (
Calculating the size of an image file
: width in pixels x height in pixels x bit depth
- 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).
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
Needed to work out the
Example: if x == 3
y == 6 print ("They are correct)
AND Logic Gate:
NOT Logic Gate:
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:
bit = b
byte = B