Computer Data Representation
Computer Data Representation
Number Systems
Binary System
A point to be noted is that the most left bit is called the MSB (Most
Significant Bit)
Denary System
Number Conversions
12 6 3 1
8 4 2 1
8 4 2 6
1 1 1 0 1 1 1 0
As can be seen it starts from 1 and then goes to 128 from left to
right
Now values with 1 are to be added together, giving the final answer,
as for the example, it is 128 + 64 + 32 + 8 + 4 + 2 = 238
14
2
2
Remainde
2 71 0
r:
Remainde
2 35 1
r:
Remainde
2 17 1
r:
Remainde
2 8 1
r:
Remainde
2 4 0
r:
Remainde
2 2 0
r:
Remainde
2 1 0
r:
Remainde
0 1
r:
When you reach 0, the remainder has to be read from bottom to top
giving us the binary value ( as in this case, it is 1 0 0 0 1 1 1 0 )
Separate each value from each other and convert them to denary
e.g.
Explain
Hexadecimal : 2 1 F D
Denary :2 1 15 13
Divide the binary value into groups of 4 starting from the right. If at
the end, the last division is less than 4, add 0s until it reaches 4
For each group, find the denary value as shown above, and then
convert each denary value to its corresponding hexadecimal value
(if less than 10, then itself, else, 10 is A, 11 is B, 12 is C, 13 is D, 14
is E and 15 is F).
After conversion, just put all the hexadecimal values in order to get
the final answer
Explain
Given Value : 1 0 0 0 0 1 1 1 1 1 1 1 0 1
Convert the value to binary as shown above, and then convert the
final answer to denary
Binary Calculations
Binary values are not added the way denary values are added, as
when adding 1 and 1, we cannot write two because it doesn’t exist
in binary.
Points to Note:
0+0=0
1+0/0+1=1
1 + 1 = 0 (1 carry)
1 + 1 + 1 = 1 (1 carry)
Overflow
When adding two values, if the solution exceeds the limit of given
values, e.g., the solution has 9 bits, but the question had 8 bits per
value, the 9th bit (most left bit) is called overflow.
This indicates that the memory doesn’t have enough space to store
the answer to the addition done in the previous part.
1. Convert both the bytes into 8 bits (add zero to the left-hand
side to match them).
Carry 1 1 1 1 1 1 1
Byte 1 0 1 1 0 1 1 1 0
Byte 2 1 1 0 1 1 1 1 0
OVERFLO
W
Soluti
1 0 1 0 0 1 1 0 0
on
Note: We move from RHS to LHS, and when adding values, we use the
rules given above. If the bit crosses the limit (overflows), we put the value
in brackets, denoting it is overflow.
iii. The solution would now be (1) 0 1 0 0 1 1 0 0
Logical Shifts
The logical shift means moving a binary value to the left or the right
When doing a logical shift, keep in mind that the bit being emptied
is going to become 0
Firstly, write the binary value and locate the first one from the right;
e.g., 1101100 would have the first one at the third position from the
right.
Now, switch every value to the left of the first one located above
(not switching the one), e.g., the value in our example becomes
0010100, which is the two’s complement of itself.
1 0 1 1 1 0 1 0
-128 + 32 + 16 + 8 + 2 = -70
Examples:
Memory Dumps
Memory Dumps
Using hexadecimal makes writing code easier, faster, and less error-
prone than binary.
Using machine code (binary) takes a long time to key in values and
is prone to errors.
ASCII
The standard ASCII code character set consists of 7-bit code that
represents the letters, numbers and characters found on a standard
keyboard, together with 32 control codes
0 is at 48
A is at 65
a is at 97
Unicode
Sound
The sound waves are sampled at regular time intervals where the
amplitude is measured. However, it cannot be measured precisely,
so approximate values are stored
Sampling Resolution:
Sampling Rate
Images
Bitmap Images
Colour Depth
An 8-bit colour depth means that each pixel can be one of 256
colours (because 2 to the power of 8 = 256)
A 1-bit colour depth means each pixel can store one colour (because
2 to the power of 1 is 2) - ( This is done as the bit can either be 0 or
1, with 0 being white and 1 being black)
Increasing colour depth increases the size of the file when storing an
image.
Image Resolution
Photographs with a lower resolution have less detail than those with
a higher resolution.
8 bits is a byte
4 bits is a nibble
Conventional System
Name of memory No. of Equivalent Denary
size Bytes Value
The size of a mono sound file is calculated as sample rate (in Hz) ×
sample resolution (in bits) × length of sample (in seconds). (For a
stereo sound file, you would then multiply the result by two.)
File Types
o The first byte is the status byte – which informs the MIDI
device what function to perform
MP3
Use lossy format as the original file is lost following the compression
algorithm
MP4
This format allows the storage of multimedia files rather than just
sound
JPEG will reduce the raw bitmap image by a factor between 5 and 15
All the data bits from the original file are reconstructed again when
the file is uncompressed.
Important for files where the loss of data would be disastrous
(spreadsheet)
No data is lost
Run-Length Encoding
One difficulty is that RLE compression isn't perfect for strings like
"cdcdcdcdcd". We use a flag to solve this; e.g., 255 can be made as
the flag. Now 255 will be put before every repeating value, e.g. our
previous example becomes 255 05 97 255 04 98 255 02 99 255 05
100 where 255 now indicates that the next character/set of
characters is approaching