1A - Graphics Sound Twos Complement Data Compressions
1A - Graphics Sound Twos Complement Data Compressions
1. Most Significant bit (MSB) - this is the bit in the binary number which is on the leftmost side of the bnary number and it carries the highest
denary weight
2. Least Significant bit(LSB) - this is the bit on the rightmost side. It carries the lowest denary weight of one
Conversion
You will need to know how to convert from one number system to another:
We will talk about how each on is done briefly and I will also put a video for you to watch at the end of the chapter
Binary to Denary
Let's take a simple binary number
00110011
The binary value has a place value of 2x
The LSB has a weight of 1 and the 2nd bit has a weight of 2 and so on
So whenever there is a 1 you take that particular place value weight of that digit
Then take the sum of all the weights and it will give you the denary value
0 0 1 1 0 0 1 1
- - 32 16 - - 2 1
32+16+2+1 = 51
There is also another method you can follow
00110011
You start with the MSB
After you find the value you add either 1 or 0 depending on the next bit
Then the new value is multiplied by 2 again and the whole process continues
When you receive the last digit(LSB) you just add the bit to the value and this gives you the denary value
0 * 2 = 0
(add 0)
0 * 2 = 0
(add 1)
1 * 2 = 2
(add 1)
3 * 2 = 6
(add 0)
6 * 2 = 12
(add 0)
12* 2 = 24
(add 1)
25* 2 = 50
(Finally just add 1)
50 +1 = 51
This is my opinion a good method to follow
Denary to binary
There are also two methods for this
So we keep dividing the denary value by 2. We will sometimes get a remainder of 1 or 0. Then you read the remainders from the bottom
to the top which gives us the binary number
2|254
2|127 → 0
2|63 → 1
2|31 → 1
2|15 → 1
2|7 → 1
2|3 → 1
2|1 → 1
0 → 1
These requires you to know the binary weight properly such as 1 , 2 , 4 , 8 , 16 , 32....
This is very useful to convert a decimal number to a binary number (This is an A2 topic so we will discuss that later)
254 - 128 → 1
126 - 64 → 1
62 - 32 → 1
30 - 16 → 1
14 - 8 → 1
6 - 4 → 1
2 - 2 → 1
0 - 1 → 0 // as 0 is not large enough to reduct 1
from it
For this method we read from top to bottom
Binary to Hex
This is the easiest conversion
We group the binary numbers to nibbles starting from the right and we find the denary value of each nibble and this is converted to Hex (
very similar to BCD )
0011011
As we can see, this has 7 bits so how can we group in 4 bits
(0)001 1011
You need to add a 0 to the start to make it 4bits
0001 1011
1 11
1 B
= 1B16
To convert from Hex to binary follow the reverse order
1 B
1 11
0001 1011
Its better to convert denary to binary then Hex ( vice versa ) as this is more simpler and less error prone
Prefixes
Same as physics, we don't like to give storage or other specifications in large numbers, we usually like to give it in 1 d.p
kilo 103 KB
Mega 106 MB
Giga 109 GB
Tera 1012 TB
This table uses Bytes as an example
This means that the size of data is grouped in quantities and the prefix tells us the size of data
However, recent questions don't ask this now but, lets see one example
200000/8 = 25000Bytes
25000/1000000 = 0.025MB
But now we use binary prefixes because it is the correct way of representing quantities
Prefix Magnitude Symbol
200000/8 = 25000Bytes
25000/1024 = 24.4KiB
24.4/1024 = 0.024MiB
So really they will usually specify which one they want. If they say KB use denary prefixes. If they use KiB use binary prefixes
Also if they say Mib instead of MiB it means they want Mebibits not Mebibytes and so you don't have to divide by 8
There are two types of integer which the computer can store - unsigned and signed integer
Signed integers are integers which can be either positive or negative whereas unsigned integer is always positive
The Most significant bit determines the sign ( 1 - negative and 0 - positive ) where as the rest of the bits define the magnitude
If it is not a signed integer we just use normal conversions like the above examples
So most questions give the byte in a sign and magnitude form ( unless they state the form ) and this must be converted to two's
complement
10011110
Remeber this is in sign and magnitude form
Before you know how to convert it we need to first define 2's complement
Two's Complement
This is one's complement plus 1
What is one's complement?
One's complement is when the bits in a byte are substracted from 1 ( so making a 1 to 0 and 0 to 1
An example is 00100100 is converted to 11011011 - so every bit is changed
10011100
Ignore the first 0's on the right side
So we will get:
01100 100
The first 0's and the first 1 doesn't change
This is a much easier method and usually used to change negative sign and magnitude binary numbers
However you use this method only when the sign and magnitude is negative, infact this is a very confusing part
If the binary number is positive then the sign and magnitude is the same as the two's complement form
So for this we need to use the above method and so you will get 01101110
However this is not the answer because the first bit(MSB) is changed from 1 to 0 and so it will become a positive number
For this reason the Two's complement should have the same sign as the sign and magnitude form
To convert a 2's complement to the corresponding denary value can be done by reversing the process such as finding the sign and
magitude form and then finding the denary value
Or
The below binary value is in 2's complement. Find the denary value
11011010
The most significant bit is 1 so the number is negative
First find the value of the sign which is negative and then add the positive value of the magnitude(remaining bits)
So this makes sense why the sign and magitude of positive number is the same as the two's complement
The below binary value is in 2's complement. Find the denary value
01011010
By following the same method above we will get 38
I don't know if textbooks follow this explanation but in my opinion this is the most simplest explanation I could give
Properties
There are some properties of 2's complement and sign and magnitude you need to know
Two's complement has only one representation for 0 where as sign and magnitude have two forms - one for -0 and one for 0. This is
actually an advantage of two's complement
The maximum value which can be represented for signed integers using 4 bits is 2n-1 = 7
Binary aritmethics
Lets see an example
01011101
01111011+
________
11011000
To do this just follow the normal addition
There is a pattern if you can see if the summed value is a multiple of 2 then we get 0 if not we get 1
The carry is the number of 2's which can fit the summed value
don't worry I will include a video for all these calculations below
There is also another longer method and that includes converting the binary number to denary and doing the calculation
01111101
01111011-
________
00000010
Binary substraction begins from the right side to the left side
If 1 - 0 then it would be 1
If 1 - 1 then it would be 0
Overflow errors
It is when the result of a calculation is larger than the number of bits used to define the storage for the
result
So sometimes when you add 2 binary number the result may have more number of bits
1111
1111+
_____
(1)1110
Sometimes these overflow can cause the result to become negative when we add two positive numbers
0111
0111+
_____
1110
Or when two negative numbers are added it can produce a positive number
10100000
10100000+
________
(1)01000000
The (1) will not be recorded as it won't fit in the storage, so then computer will read this as a positive number which is wrong
Both of these examples are overflow errors and the processor must be able to identify these - we will see them more in Assembly
language chapter
BCD - Binary coded decimal
Denary digits are represented using nibbles or 4 bits
If the nibble contains a value of more than 9 then it is called an invalid BCD
There are 2 types of BCD - packed BCD or one BCD per byte
In packed BCD it means that 2 digits of denary can be represented using 1 byte, whereas in one BCD per byte only one digit is
represented(the remaining bits are 0's)
Example, Packed BCD - 11011001 and One BCD per byte - 11010000
0010 1001
Each nibble could be converted to the corresponding denary value
0010 1001
2 9
You also need to know how to perform calculations and addition with BCD
When we do addition with BCD we isolate each nibble such as the example below
29 + 45
We can see that 1110 that this is an invalid BCD 1110 which has a value of 14. So this must be corrected by adding 0110 or 6
We can see after adding 0110 we get a carry of 1 which taken to the next BCD and added
If the next BCD also was invalid then we had to add 0110 and 1 = 0111 and there will be a carry to the next BCD
Internal coding of character
There are two ways which text and characters can be represented
ASCII
Originally ASCII uses 7 bits to store each character(this is known as the ANSI ASCII)
The bits required to store each ASCII character are known as character codes
This could be used to represent 128 different characters which is enough to represent the english set and numbers and other command
keys
The new ASCII is called the Extended ASCII as it is used to represent modified alphabets such as the ISO - Latin characters
This uses 8 bits or 1 byte to store each character and this could represent 256 characters
This is still not enough to represent other characters from different languages
Unicode
The standard uses 2 bytes to store each character allowing 65536 possible characters
However most of the time its usually less as some bits are required to describe the encoding used
UTF - 8 and UTF - 16 bits means that in UTF - 8 the system handles each 8 bits at a time.
Unicode is able to represent all the characters in the world and many other language so it used more commonly than ASCII
Unicode code point are usually represented using Hexadecimals - for example U - FFFF
Notes in ASCII
All you need to know is ASCII is enough to represent the english character set and numbers and some commands
Characters which are in sequence are changed by the ASCII value of 1 - Ex A and B are only different by one value
The difference between the uppercase and lowercase ASCII characters is in bit 5 - Ex (A=65) where as (a=97) so difference in 32
Representation of graphics
There are 2 types of graphics:
Vector Graphics
Vector graphics are stored in the SVG format and requires a graphic plotter to output them directly
Vector graphics are relative to the canvas and so it is scalable without geting distorted and pixelated
Also when image is scaled both the dimensions are scaled so the image doesn't get squashed or stretched
Another important point is that vector graphics uses a lot of processing power however less storage compared to BMP graphics and it is
also used to represent simple images such as shapes
If an vector graphics must be displayed on a screen or printed then it must be be converted to bitmap form
Bitmap Graphics
An image which is made out of elements or components called pixels which stores a color and its
position in the BMP matrix
The pixels are displayed in a 2D matrix where the color of each pixel and its position in the 2D matrix is stored
Pixel is the smallest component which is identified using its color and position in the 2D matrix
So each pixel can represent a color and the number of bits required to store each pixel is known as color depth
For example 24 bit color depth means that 224 colors can be represented
Some questions use the word bit depth for images and this means the number of bits required to store each primary color
For example if you have a bit depth of 8 bits it means it requires 8 bits to store each primary color of RGB and so the color depth will be 24
bits
Bit depth is the number of its required to store each primary color
So back to BMP images it is made of many tiny pixels in a 2D matrix. To find the number of pixels in a image we need to find the product of
the pixel high and pixel wide of an image, this is known as the image resolution
Image resolution is the product of the number of pixels high and number of pixels wide an image is
In a simpler terms, it means how many pixels are there in an image
The screen resolution is the product of the number of pixels high and number of pixels wide the
screen can display
So whatever we see through the screen, it is limited by the screen resolutuion - for example if the screen is 2K but the image is 4K we will
only see a 2K image
There are some points on Bitmap graphics - it uses the file extension .BMP(raw file) where as the compressed versions are .PNG and .JPG
Also the bitmap images can be enlargened but, when we enlarge the image even the pixels are enlarged and so the image seems
pixelated and distorted
Bitmap images are good for storing photographs and pictures but uses way alot of storage
Image file size
They will ask us to calculate the file size of an image
We find the number of pixels(using the image resolution) and multiply it by the color depth
Depending on what you took for the color depth ( if we took it in bits ) then the file size will be in bits
In my opinion it's better to use bytes as you may have to convert it to MiB
What is the image size if the pixel height is 500 and the pixels wide 1000 and the color depth is 24 bits
Notice that i used 3bytes instead of 24 bits so my final answer will be in bytes
File header
The above calculated value gives the space required only to store the graphics however at the start of the file there is a file header which
provides metadata of the file
Number of bits at the start of a image file which is used to define the coding used such as the color
depth and the resolution
These are the things defined by the file header:
1. Image resolution
Sound Representation
Sound waves in the air are analogue waves which contain a range of values and amplitudes and must be converted to the digital forms, we
will discuss each point in detail
Sampling
It is taking regular measurements of amplitudes at set timed intervals (regular intervals)
So for the ADC convertor to convert from analogue signals to digital it must take the amplitude at regular intervals and digitise them to
binary.
Another point to remember that there is usually a band-limiting filter in the sound encoder(instrument for recording and digitising sound) to
remove high frequency which can not be heard by the human ear
Sampling Rate
This is also known as sampling frequency
Sampling resolution
The number of bits required to store each sample
This is also known as bit depth
The definition is easy however the understanding is also required - greater bits required to store each samples means more possibilities of
amplitude can be recorded, this means if 3 bits are used to store each sample, then the sample can represent 8 different sound levels or
amplitudes
Usually 16 bits are required for good quality and to avoid any quantinising errors
The channel parts are usually not asked - but it could be either 1 or 2
The duration means the time length of the sound
Again if we use bits for the sampling resolution we get the answer in bits
Lossless Compression
This when no data is removed and the process could be reversed to obtain the original file - these
include RLE and Huffman coding algorithms
Usually there are two algorithms used for lossless compression:
RLE - Run length encoding is done by specifying the number of times a character is repeated followed by the value of the character
RLE is not strictly marked as it is the concept which matters, usually RLE can be in Hex or Binary and the order of the representation
doesn't really matter - so 8A is same as A8
Huffman coding - this replaces the most frequently used characters or words with shorter codes
Usually we have a table which contains the character which is being replaced and their shorter codes
Huffman coding can be used for sound also to replace most frequent amplitudes with shorter codes
Lossy Compression
This method removes unnecessary data which the process can not be reversed to obtain the original
file
This is done by reducing the image or sound quality by reducing the color depth or the sampling resolutions
Using perceptual shaping where frequency which are inaudible are either removed or stored with lower sampling resolutions
Recommended
These are things you might like. Clicking these ads can help us improve our free services in the future...