Topic 2: Data Flashcards
Why Binary?
Computers contain billions of transistors. These act as switches that have two states: on and off. These states are then represented in binary by 1(on) or 0(off). These are called bits.
Binary naming
Bits ( 1 bit)
Nibble ( 4 bits)
Byte (8 bits)
An arithmetic expression to show that 256 different colours can be represented in 8 bits
2¡(nr of bits) –> 2¡8
How to convert 6 to binary
0 1 1 0
Convert 78 into binary
0 1 0 0 1 1 1 0
1101 1001 into denary
128—64—-32—-16—–8—–4—–2—–1
——————————————————
1——1—–0——1——1—–0—–0—–1
——————————————————
128 + 64 + 6 + 8 + 1 = 217
Two’s complement signed integers
-Remove the - sign
-Convert the number to binary
-Flip the bits
-Add 1
How to represent -4 in binary
0 1 0 0 (convert +4 to binary)
1 0 1 1 (flip the bits)
1 1 0 0 (add 1)
Binary addition
0 + 0 = 0
0 + 1 = 1
1 + 1 = 0 and carry 1
Logical shift left by 2 places: 0001 0100
0101 0000
Logical shift right by 3 places: 1011 1000
0001 0111
Arithemtic shift right by 1 place: 1000 1000
1100 0100
Overflow
when an operation produces a result which requires more bits than available to store result
Consequences of overflow
Programs may crash or produce unreliable or incorrect results
1 reason why the result of adding 16 bit patterns must be 16 bit in length
The registers inside the machine that hold the original patterns are fixed in width, and so no more that 16 bits can be held.
Hexadecimal (10-16)
A-F
Convert C3 to binary
1) Each hexadecimal digit is converted to denary (C = 12) and 3)
2) Each denary number is converted into a nibble (1100)(0011)
3) The nibbles are combined to five the binary number (1100 0011)
ASCII in python
ord() returns the ASCII code in denary (“c”)–> 99
chr() returns the character for a denary code 100–> (“d”)
Upper case characters
65-90
Lower case characters
97-122
Digits 0 to 9
48-57
Image file size equation
W (width) * H (height) * D (colour depth)
Pixel
- PICture ELement
- Each pixel has its own individual colour
- The greater the number of pixels, the greater the detail
Colour depth
the number of bits used to encode the colour of each pixel
Resolution
- number of pixels per inch when
- e.g on a monitor or on paper
calculate size of image with:
- 24-bit colour depth
- 410 * 270 pixels
in (MiB)
(410 x270x24) / (8x1024x1024)
2 Factors that affect quality of a digital image
- Nr of pixels that make it up (more pixels more resolution)
- Nr of bits used to encode the colour of each pixel (more bits used, more colours can be displayed)
Sample interval
samples of a sound wave taken at regular fixed intervals
Sample rate
number of samples over a given time period
Analogue recordings
convert the changes in air pressure into voltage changes
Audio file size equation
file size (bits) = sample rate * bit depth * recording length (seconds)
CDs sample rate
44 100 per second (44.1 kHz)
Blu-ray sample rate
96 000 per second (96 kHz)
CDs important info
They are recorded in STEREO and so have two channels.
Total file size needs to be doubled
Calculate size in MiB digital audio file of
- 3 minutes
- 44.1 kHz sample rate
- 16 bits of bit depth
(44 100 * (3*60) * 16) / (8 * 1024 * 1024)
Why analogue signal is never fully reproducible
It is recorded at fixed intervals (sample frequency)
Therefore the entire analogue signal is not represented in the digital recording.
Nr of values of unsigned integers
4 bits (0 to 15)
8 bits (0 to 255)
Nr of values of signed integers
4 bits (-7 to 8)
8 bits (-127 to 128)
One reason that a 5-bit colour depth is needed to store 24 colours in an image
because 2¡4 = 16, which is less than 24
and 2¡5 = 32, which is the next largest power of 2 greater than 24
Conversion units
Byte
Kibibyte (KiB)
Mebibyte (MiB)
Gibibyte (GiB)
Tebibyte (TiB)
How to convert units
multiply or divide by 1024
32 GiB to bits
32 * 1024 * 1024 * 1024 * 8
Lossless compresion
- Reduces file sizes without deleting any data
- Nothing is lost
Lossy compression
- Reduces file size by deleting some data.
- The original can never be reconstituted (it has been irreversibly changed)
How is lossless compressed?
- Looks for redundancy where the same data is stored many times and groups this data into one reference
How is lossy compressed?
- In image files, algorithms analyse the image and find areas where there are only slight differences. These are given the same value and the file can be rewritten using fewer bits.
- In digital sound recordings, very small variations in frequency, tone and volume are removed to reduce the file size as the human ear cannot detect these small differences.
Uses of lossless compression
- Text files
- Graphic files with a low colour depth
Uses of lossy compression
- Image files
- DIgital sound recordings
Less successful uses of lossles compression
- Audio files
- 24-bit colour files
Less successful uses of lossy compression
- Text files
- Executable software
Examples of lossless compression
- Compressed text files
- GIF and PNG image files
- FLAC and ALAC audio files
Examples of lossy compression
- MP3 audio files
- JPG image files
Advantages of file compression :
- less internet bandwidth
- transfer time is faster
- less storage
- reduce congestion on the internet
- audio and video files can be streamed
Differences between lossy and lossless
In lossy:
- when uncompressed it is not exactly the same as the original
- for example audio files (MP3) or image files (JPG)
In lossless:
- when uncompressed, it is restored completely as the original
- for example compressed text files