0% found this document useful (0 votes)
54 views

1 Data Representation - L1 - Introduction To Number System

The document discusses different number systems including decimal, binary, octal and hexadecimal. It explains how to convert between these number systems using algorithms and lookup tables. Conversion methods covered include decimal to binary, binary to decimal, binary to hexadecimal, hexadecimal to binary and hexadecimal to decimal.

Uploaded by

anika t
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

1 Data Representation - L1 - Introduction To Number System

The document discusses different number systems including decimal, binary, octal and hexadecimal. It explains how to convert between these number systems using algorithms and lookup tables. Conversion methods covered include decimal to binary, binary to decimal, binary to hexadecimal, hexadecimal to binary and hexadecimal to decimal.

Uploaded by

anika t
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 50

01 Number System

What is a
computer?
1. Number System
• A numeral system (or system of numeration) is a writing system
for expressing numbers.
• The number (numeral) represents is called its value.
• In digital electronics, the number system is used for representing
the information.
• The number system has different bases and the most common of
them are the decimal, binary, octal, and hexadecimal.
• The base or radix of the number system is the total number of
the digit used in the number system.
Decimal Number Systems
• This number system is known as a decimal
number system because total ten digits are
involved.
• The base of the decimal number system is 10.
Range of Decimal Numbers: 0123456789
Binary Number Systems
• The modern computers do not process decimal number; they work with
binary number system which uses only two digits 0 and1.
• The base of binary number system is 2.
• The range of digits in Binary number system is :
– 0 to (radix -1)
– 0 to (2-1)
– 0 to 1

• That is Binary number system is having digits


0, 1
Range of binary numbers: 01
Micro Transistors
1 0

Tally counting - 8
ON OFF
Decimal system - 8
Binary System - 28 = 256
1 0 1 1 0 0 1 1
28 = 256
0 to 255

Byte = 8 bit

= BIT

BInary digiT
3. Octal Numbers
• The base of the Octal number system is 8.
• The range of digits in the Octal number system is :
– 0 to (radix -1)
– 0 to (8-1)
– 0 to 7
• That is Octal number system is having digit
0, 1, 2, 3, 4, 5, 6, 7
4. Hexadecimal Numbers
• The hexadecimal number system has a base of 16.
• These numbers are used extensively in microprocessor work.
• Range of Hexadecimal Numbers is :
– 0 to (radix -1)
– 0 to (16-1)
– 0 to 15
• The range of digits in Hexadecimal number system
• It consists of the following sixteen number of digits.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
SUMMARY
Decimal Binary Octal Hexadecimal

0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
The table is shows the 5 0101 5 5
decimal, binary, octal, 6 0110 6 6
and hexadecimal 7 0111 7 7
numbers from 0 to 15. 8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
02 Number System
How to Convert Decimal to Binary?
• The given decimal number is divided repeatedly by 2 and the remainders are noted down till we get 0 as the
final quotient.
• Step 1: Divide the given decimal number by 2 and note down the remainder.
• Step 2: Now, divide the obtained quotient by 2, and note the remainder again.
• Step 3: Repeat the above steps until you get 0 as the quotient.
• Step 4: Now, write the remainders in such a way that the last remainder is written
first, followed by the rest in the reverse order.
( LSB of the binary number is at the top and the
MSB is at the bottom)
1. Convert the Decimal Number 52 to its binary equivalent.
2. Convert the Decimal Number 151 to its binary equivalent
03 Number System
Descending Powers of Two and Subtraction
1. Start by making a power chart of 2.
2. Look for the greatest power of 2.
3. Move to the next lower power of two.
4. Subtract each successive number that can fit, and
mark it with a 1.
5. Continue until you reach the end of your chart.
6. Write out the binary answer.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2

32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1

4 Number System
Algorithm

1. Write down the binary number and list the powers of 2


from right to left.
2. Write the digits of the binary number below their
corresponding powers of two.
3. Connect the digits in the binary number with their
corresponding powers of two.
4. Write down the final value of each power of two.
5. Add the final values.
Convert the Binary Number 11100 to its decimal equivalent.
SUMMARY
Binary integers to decimal: Algorithm
1. Write down the binary number and list the powers of 2
from right to left.
2. Write the digits of the binary number below their
corresponding powers of two.
3. Connect the digits in the binary number with their
corresponding powers of two.
4. Write down the final value of each power of two.
5. Add the final values.
5
Decimal Binary Octal Hexadecimal

0 0000 0 0
1 0001 1 1

Number System 2 0010 2 2


3 0011 3 3
The table is shows the 4 0100 4 4

decimal, binary, octal, and 5 0101 5 5

hexadecimal numbers from 0 to 15. 6 0110 6 6


7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Decimal to Binary Conversion
• To convert a Denary number to Hexadecimal we should follow two steps
– Denary to Binary Conversion
– Binary to Hexadecimal Conversion
1. Start by making a power chart of 2.
2. Look for the greatest power of 2.
3. Move to the next lower power of two.
4. Subtract each successive number that can fit, and mark it with a 1.
5. Continue until you reach the end of your chart.
6. Write out the binary answer.
2. How to Convert Binary to Hex
• Converting from binary to hex is easy since
hexadecimal numbers are simplified versions of binary
strings. You just need to remember that each hex digit
represents four binary digits.

• It follows that four binary digits will be equal to one hex


digit. The method is easier than it sounds but it’s always
useful to use a binary to hex conversion chart to save time.
2. Algorithm to Convert Binary to Hex

• Step 1: Write down the binary number and group the


digits (0’s and 1’s) in sets of four.
• Step 2: Every group of four in binary will give you one
digit in hexadecimal.
• Step 3: Add the products within each set of four. Write the
sums below the groups they belong to.
• Step 4: The digits you get from the sums in each group
will give you the hexadecimal number, from left to right.
6 Number System
How to Convert Hex to Binary
• straightforward since hexadecimal
numbers are simplified versions of binary
strings. You just need to remember that
each hex value will produce four binary
digits.

Advantage of a Hexadecimal Number


• The main advantage of a Hexadecimal Number is that it is very compact and by
using a base of 16 means that the number of digits used to represent a given
number is usually less than in binary or decimal.
• Also, it is quick and easy to convert between hexadecimal numbers and binary.
Algorithm to Convert Hex to Binary
• Step 1: Write down the hex number. If there are any, change the hex values represented
by letters to their decimal equivalents.
• Step 2: Each hex digit represents four binary digits and therefore is equal to a power of
2. The rightmost digit equals to 20 (1), the next one equals to 21 (2), the next one equals
to 22 (4) and the leftmost one equals to 23 (8). Write these numbers (8, 4, 2 and 1) below
the hex values.
• Step 3: Determine which powers of two (8, 4, 2 or 1) sum up to your hex digits. For
example, if one of your hex values is 10, this means 8 and 2 sum up to 10 (4 and 1 are
not used). If your hex number is 2, only 2 is used; 8, 4 and 1 are not.
• Step 4: Write down 1 below those 8, 4, 2 and 1’s that are used. Write down 0 below
those that are not used.
• Step 5: Read the 1’s and 0’s from left to right to get the binary equivalent of the given
hex number.
7 Number System
Binary addition
• Now that we know binary numbers, we will learn how to add them. Binary addition is much like your
normal everyday addition (decimal addition), except that it carries on a value of 2 instead of a value of 10.
• For example: in decimal addition, if you add 8 + 2 you get ten, which you write as 10; in the sum this gives
a digit 0 and a carry of 1. Something similar happens in binary addition when you add 1 and 1; the result is
two (as always), but since two is written as 10 in binary, we get, after summing 1 + 1 in binary, a digit 0 and
a carry of 1.
1’s Complement of a Binary Number:
• There is a simple algorithm to convert a binary number into 1’s complement.
• To get 1’s complement of a binary number, simply invert the given number.
• You can simply implement logic circuit using only NOT gate for each bit of
Binary number input.
2’s Complementation in Signed Binary number
Representation
• Positive numbers are simply represented as simple Binary representation.
• But if the number is negative then it is represented using 2’s complement.
• There is a simple algorithm to convert a binary number into 2’s complement.
• To get 2’s complement of a binary number, simply invert the given number and
add 1 to the least significant bit (LSB) of given result.
Register
• A register acts as a temporary storage device for a group of data bits.
• A shift register is used to move data to the left or to the right by one bit at a time.

Left Shift Operation


Right Shift Operation
• Data is shifted in the left-
• Data is shifted in the right-
hand direction one bit at
hand direction one bit at
a time with each transition of the
a time with each transition of the
clock signal.
clock signal.
Negative binary numbers
• We represent negative binary numbers using a minus symbol in front
of them. In computer number representation, these numbers can be
distinguishable with the help of an extra bit or flag called sign bit or
sign flag in the Binary number representation system for signed
numbers.
• This extra bit is called sign bit or sign flag which has a value of sign
bit is 0 for positive numbers and 1 for negative binary numbers.
Ways to represent magnitudes
There are tthree ways to represent signed binary number:
1. Sign-Magnitude method,
2. 1’s Complement method, and
8 Number System
3. 2’s complement method.
1. Signed Magnitude Method
We only add an extra sign bit at the MSB to recognize negative and positive numbers.

Sign bit has


• 1 for negative number and
• 0 for positive number.
• For signed binary numbers the most significant bit (MSB) is used as the sign bit.

• If the sign bit is “0”, this means the number is positive in value.

• If the sign bit is “1”, then the number is negative in value.

• The remaining bits in the number are used to represent the magnitude of the binary number in the usual
unsigned binary number format way.
• Then we can see that the Sign-and-Magnitude (SM) notation stores
positive and negative values by dividing the “n” total bits into two parts:
– 1 bit for the sign and
• n–1 bits for the value which is a pure binary number.
• For example, the decimal number 53 can be expressed as an 8-bit signed binary
number as follows.
Negative Signed Binary Numbers
Positive Signed Binary Numbers
2’s Complement Method

• Please note that MSB is always Sign bit, if it 0, then there are no changes.
• MSB is always 1 in case of negative numbers.
• We only take 2’s complement of negative numbers to represent in the computer.
Text Data Representation
• All alpha-numeric data and special
characters are each assigned a specific
binary value, called a character code.
4 Bits = 1 Nibble or 1 Word

• The coding scheme is a Standard


which tells the user's machine which
character represents which set of
bytes. The two common coding
schemes are
1. ASCII

92. Unicode

Character Storage
• ASCII (American Standard Code
for Information Interchange) is a
coding system for representing
characters.

• Each ASCII character has a


number between 0 and 255, and
the representation for the
character the number converted
to an 8 bit binary number.

• ASCII is also a fixed length


encoding scheme – every
character in ASCII is represented
using 8 bits.
Unicode
• Unicode is a 16 bit sequencing
provides a unique number for
every character across languages
and scripts, making almost all
characters accessible across
platforms, programs, and devices.

• Unicode provides a unique number


for every character including
punctuation marks, mathematical
symbols, technical symbols,
arrows, and characters making up
non-Latin alphabets such as Thai,
Chinese, or Arabic script.
Chapter 1 : Data Representation

Converting Image to
Binary

10 Image Storage
PIXELS
• To store an image on a computer, the image is first broken
0 for white and 1 for black
down into tiny elements called PIXELS.
• The smallest element in a picture or image is called Pixel
• (in short of Picture Element = Pixel).
• The number of pixels is the product of height and width of
an image
• (In other words, we can say it’s calculated using image
resolution).
• Ex: If your image resolution is 1020 x 800(width x height),
the total number of pixels is 816,000.
Monochrome
• For every pixel, an average color is found and a binary
value is assigned.

• For monochrome(two-color) image, only 1 bit is needed to


represent each pixel.
• 0 for white and 1 for black.
Color matrix is the binary representation of the image
Colored images
• For every pixel, an average color is found and a binary value is assigned.
• For colored images, each pixel is represented by multiple bits, one combination per shade.
Color depth or Bit depth
• The number of bits allocated for each pixel color is called color depth or bit depth(in simple words, how many bits
represent each pixel).
• If the color depth of an image is 8-bit, the image contains 256 colors.
• The most common color depths you see are
– 8-bit (2⁸ = 256 colors),
– 16-bit (2¹⁶ = 65,536 colors) and
– 24-bit (2²⁴ = 16.7 million colors).
• Larger color depth allows more shades and different colors.
• You can find the color depth or bit depth of your image from your image properties.
• For example, for an image that uses 4 colors(2² = 4), 2 bits(color depth is 2-bit) are needed for each pixel. So,
in this case, we can have,
– 00-white;
– 01-black;
– 10-yellow;
– 11-blue;
• Similarly, for a color depth of 3, we have 8
colors which are black, red, green, yellow, blue,
magenta, cyan, and white,
Metadata
• Metadata is the data about data or
extra piece of information of the
image like Resolution and Color
depth.
• You can find metadata of your image
from image details.
Image Resolution (dpi - dots per inch)
• Image Resolution, or dpi, is the
amount of dots per square inch of an
image when it is printed.
11 File size What is an image file?
• An image file is a digital representation of a
picture, and we can display it on a screen
Resolution chart like a computer monitor or a phone screen.
• Image files contain data about a picture's
attributes, like the colors present in it,
brightness and contrast, and much more.
These data are stored in what we call bits.
Image types
Image files can come in many different file
formats that we can group into two categories:
1. Raster images
2. Vector images
• Raster image
• A raster image file contains an array of pixels of various colors arranged in a
grid to form a picture.
• Pixels are tiny dots that are pretty much similar to the small X stitches in a
cross-stitch pattern.
• Vector image
• Vector images consist of attributes like curves, paths, shapes, line or stroke
thicknesses, colors, etc., that are stored in formulas or equations, not in pixels.
• This means no matter the size or how 1. farJPEG
zoomed in the
(or JPG) image
- Joint is, the lines,
Photographic Experts Group
curves, and points remain smooth. 2. PNG - Portable Network Graphics
3. GIF - Graphics Interchange Format
4. TIFF - Tagged Image File
5. PSD - Photoshop Document
6. PDF - Portable Document Format
7. EPS - Encapsulated Postscript
8. AI - Adobe Illustrator Document
9. INDD - Adobe Indesign Document
10. RAW - Raw Image Formats
11. SVG - Scalable Vector Graphics
Understanding image file sizes
• Two parameters define a raster image's file size, and these are
1. number of pixels in the image
2. bit depth of each pixel
• To determine the file size of a raster image file, we have to multiply these variables
together.
How to calculate image file size?
image file size = pixel count × bit depth
pixel count = width of the image in pixels ×
height of the image in pixels
• The term resolution refers to the
total number of count of pixels
in a digital image
The image is 16‑bit colour and is 100 pixels high and 150 pixels
wide. Calculate the file size of the image in bytes, kB and MB.
width of image in pixels = 150 pixels
height of image in pixels = 100 pixels
bit depth = 16

pixel count = width of image in pixels × height of image in pixels


= 150 x 100
= 15000 pixels

image file size = pixel count × bit depth


= 15000 x 16
= 240000 bits

image file size in bytes = 240000 / 8 = 30,000 bytes


image file size in kB = 30000 / 1024 = 29.297 kilo bytes
The image is 8‑bit colour and is 1024 pixels high and 1024 pixels
wide. Calculate the file size of the image in bytes, kB and MB.
width of image in pixels = 1024 pixels
height of image in pixels = 1024 pixels
bit depth =8

pixel count = width of image in pixels × height of image in pixels


= 1024 x 1024
= 1048576 pixels

image file size = pixel count × bit depth


= 1048576 x 8
= 8388608 bits

image file size in bytes = 8388608 / 8 = 1048576 bytes


image file size in kB = 1048576 / 1024 = 1024 kilo bytes
The image is 16‑bit colour and is 1920 pixels high and 1536 pixels
wide. Calculate the file size of the image in bytes, kB and MB.
width of image in pixels = 1536 pixels
height of image in pixels = 1920 pixels
bit depth = 16

pixel count = width of image in pixels × height of image in pixels


= 1920 x 1536
= 2949120 pixels

image file size = pixel count × bit depth


= 2949120 x 16
= 47185920 bits

image file size in bytes = 47185920 / 8 = 5,898,240 bytes


image file size in kB = 5,898,240 / 1024 = 5,760 kilo bytes
There are 22 images in a folder and each image is 16 ‑bit colour and is 1920 pixels
high and 1536 pixels wide. Calculate the file size of the image in bytes, kB and MB.
width of image in pixels = 1536 pixels
height of image in pixels = 1920 pixels
bit depth = 16

pixel count of 1 image = width of image in pixels × height of image in pixels


= 1920 x 1536
= 2949120 pixels
pixel count of 22 image= 2949120 x 22 = 64880640 pixels

image file size = pixel count × bit depth


= 64880640 x 16
= 1038090240 bits

image file size in bytes = 1038090240 / 8 = 129761280 bytes


image file size in kB = 129761280 / 1024 = 126720 kilo bytes
Chapter 1 : Data Representation

Converting Voice to
Binary

12 Audio Storage
12 Audio Storage Representing sound
• Sound needs to be converted into binary for computers to be able to process it.
• To do this, the sound is captured - usually by a microphone - and then converted into a digital signal.
Analogue to Digital converter
• An ADC will sample a sound wave at regular time intervals
Audio sampling
• Audio sampling is the process of transforming a sound source (Analog) into a digital file.
• An analog-to-digital converter will capture a sound wave at regular time intervals. This recording is known as a sound
sample.
Sample rate
• The sampling rate refers to the number of samples of audio recorded every second.
• A higher sample rate provides to deliver a better-quality audio reproduction.
• Common sample rates are 44.1 kHz, 48 kHz, and 96 kHz.
• kHz stands for kilohertz, or 1000 samples per second,
• 44.1 kHz represents 44100 samples per second.
Sample resolution
• Sample resolution is the number of bits used
to represent each sample.
• If more bits are available for each sample,
then more levels of the signal can be
captured, which improves the detail of the
recording.
13 Audio Storage File size reduction
• This is a process where file size is reduced using algorithms resulting in a file that uses fewer storage bits than
the original file.
1. In a situation where one wants to send a picture to her friend, compression will be done at the source device and
decompressed at the destination device. This enables the file to be sent faster, and it reduces overhead traffic for transmitting
the data.
2. In social media apps like WhatsApp, we notice that the image received is of lower quality and consumes much lesser space.
For a few apps, we can set the quality of media to be downloaded.
3. We also notice compression in video streaming sites, where videos are loaded in low quality during poor internet
connectivity.

DATA COMPRESSION
• Data Compression is a technique in which the size of data is reduced without loss of information but at a cost of
lower quality.
• The categories of data compression methods are
1. Lossy compression
2. Lossless compression
• The lossy compression technique does not restored the data in its original form, after decompression.
• The lossless compression restores and rebuilt the data in its original form, after decompression.
Lossy Compression Lossless Compression
(irreversible compression) (reversible compression)
does not eliminate the data which is not
Eliminate the data which is not noticeable.
noticeable.
A file does not restore or rebuilt in its
A file can be restored in its original form.
original form.
Data’s quality is compromised. Does not compromise the data’s quality.

reduces the size of data. does not reduce the size of data.
used in Images, audio, video. used in Text, images, sound.
has more data-holding capacity. has less data-holding capacity
Algorithms used in Lossy compression are: Algorithms used in Lossless compression
Transform coding, Discrete Cosine Transform, are: Run Length Encoding, Lempel-Ziv-
Discrete Wavelet Transform, fractal Welch, Huffman Coding, Arithmetic encoding
compression etc. etc.
Run-length encoding (RLE)
• Run-length encoding (RLE) is a lossless compression method by
specifying the number of times a character or pixel color
repeats followed by the value of the character or pixel.
Follow the steps below is the RLE algorithm:
1. Pick the character from the source string.
2. Count the number of subsequent occurrences of the picked
character and append the count to the destination string.
3. Pick the next character and repeat steps 1, 2 and 3 if the end of the
string is NOT reached.
• For example, if the input string is
“wwwwaaadexxxxxx”

• then the function should return


“ w4 a3 d1 e1 x6 ”

You might also like