Chapter 02 (Eng)
Chapter 02 (Eng)
Number Systems
What is meant by Number System? ➢ Note: In any type, do not divide or multiply
• The system used to represent numerical data is any number by 10.
called a number system. Type 1: Conversion from Decimal to Other
• In computers, number systems provide the Systems
foundation for displaying, storing, and Method: (Division)
processing information. • To convert from Decimal to Binary, divide
Binary Number System the number by 2 and record the remainders.
• The binary system represents any value using Continue until the number is less than 2 or
two digits (0, 1). equals 0.
• It is also known as a base-2 system. • To convert from Decimal to Octal, divide the
Octal Number System number by 8 and record the remainders.
• The octal number system represents any value Continue until the number is less than 8 or
using eight digits (0, 1, 2, 3, 4, 5, 6, 7). equals 0.
• It is also called a base-8 system. • To convert from Decimal to Hexadecimal,
Decimal Number System divide the number by 16 and record the
• The decimal system represents any value using remainders. Continue until the number is less
ten digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9). than 16 or equals 0.
• It is also known as a base-10 system. Type1: Decimal to Binary Conversion
Hexadecimal Number System 27 (10) = ……. (2)
• The hexadecimal system represents any value
using sixteen digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A,
B, C, D, E, F).
• It is also referred to as a base-16 system.
Define Base in a Number System?
• The base of any system refers to the total
number of digits used in that system.
Key Points of Numbering Systems 27 (10) = 11011 (2)
• The binary numbering system is used in
computers because digital circuits operate in Type 1: Decimal to Octal Conversion
two states: ON (1) and OFF (0). Hence, all types
931 (10) = ( ۔۔۔۔۔۔۔۔۔۔۔۔۔۔8)
of data are processed in binary form by
computers.
• The decimal numbering system is commonly
used in our daily life.
• All numbering systems are positional, and the
values are arranged from right to left.
• In the binary numbering system, each digit
represents a power of 2.
• In the octal numbering system, each digit
931 (10) = 1643(8)
represents a power of 8.
• In the decimal numbering system, each digit Type 1: Decimal to Hexa-Decimal
represents a power of 10. Conversion
• In the hexadecimal numbering system, each
digit represents a power of 16. 938 (10) =....... (16)
Number System Conversion
Type 1: Questions in Decimal System
Method: Divide and record the remainders.
Type 2: Find the answer in Decimal System
Method: Multiply by powers (exponentiation).
Type 3: Both question and answer are not in
Base 10 938 (10) = 3AA (16)
• Binary to Octal:
Type 2: Conversion from Other Number
1. Create the octal table.
Systems to Decimal
2. If the question is in Base 2, group
Binary to Decimal Conversion:
digits in sets of 3 (right to left).
• Multiply each digit of the given number by
• Binary to Hexadecimal:
the power of 2 (starting with power 0 from
1. Create the hexadecimal table.
right to left).
2. If the question is in Base 2, group
digits in sets of 4 (right to left).
_______________________________________________________________________________________________
1
• Add the results of each multiplication, 2. For each octal digit, find its corresponding
incrementing the power by 1 for each binary equivalent directly from the table.
subsequent digit. Table of Binary and Octal
Octal to Decimal Conversion:
• Multiply each digit of the given number by
0 0 0 0
the power of 8 (starting with power 0 from 0 0 1 1
right to left). 0 1 0 2
• Add the results of each multiplication, 0 1 1 3
incrementing the power by 1 for each 1 0 0 4
subsequent digit. 1 0 1 5
Hexadecimal to Decimal Conversion: 1 1 0 6
• Multiply each digit of the given number by 1 1 1 7
the power of 16 (starting with power 0 from
right to left). Type 3: Binary to Octal
• Add the results of each multiplication, 10110(2) = ……… (8)
incrementing the power by 1 for each
subsequent digit. Making Group of 3 digits
Type 2: Binary to Decimal Conversion = 010110 (2)
110101 (2)= .............(10) 010 = 2
110101 (2)= 1 x 25 + 1 x 24 + 0 x 23 + 1 x 22 + 110 = 6
0 x 21 + 1 x 2 0 010110(2) = 26(8)
= 1 x 32 + 1 x 16 + 0 + 1 x 4 + 0 + 1 x 1 Type 3: Octal to Binary
= 32 + 16 + 0 + 4 + 0 + 1 406 (8) = (2)
= 53 4 = 100
_______________________________________________________________________________________________
2
Type 3: Binary to Hexa-Decimal Bytes Number 2n-1 − 1 Maximum
of Bits Formula Value
101101(2) ……… (16) 1 Byte 8 28-1 − 1 127
2 Bytes 16 216-1 − 1 32767
Making Group of 4 digits
4 Bytes 32 232-1 − 1 2,147,483,647
00101101(2)
2. Negative Integers
0010 = 2 In computer memory, negative integers are
represented using the 2's complement method.
1101 = D
How it works:
101101(2) = 2D(16) 1. Invert all bits: Convert 0 to 1 and 1 to 0.
2. Add 1 to the least significant bit (LSB) of the
Type 3: Hexa-Decimal to Binary inverted number.
3CA (16)……. (2) The value of negative integers in binary is
expressed using the formula: −2n-1-where n is the
3 = 0011 number of bits.
C = 1100 Negative Number Formula: Maximum Value
Integer of Bits −2n-1
A = 1010
1 Byte 8 −28-1 -128
3CA (16) = 001111001010(2) 2 Bytes 16 −215-1 -32,768
4 Bytes 32 −231-1 -2,147,483,648
Binary Encoding of Integers and Whole
Numbers How Floating-Point Numbers Are Stored in
1. Whole Numbers Computer Memory
Whole numbers are a set of non-negative integers, Floating-point numbers, include fractional parts or
including zero. Example: W = {0,1,2,3,...} decimal points. These are real numbers stored in a
manner similar to scientific notation.
Binary Encoding of Whole Numbers:
There are two ways to represents floating point
Data is stored in computer memory in bytes. Since
numbers.
1 byte contains 8 bits:
• Single Precision (32-bit)
• If all bits are ON (1), the binary number will
• Double Precision (64-bit)
be 11111111, which is equivalent to 255 in
decimal. 1. Single Precision (32-bit)
• If all bits are OFF (0), the binary number will In this method, 32 bits (4 bytes) are allocated to
be 00000000, which is equivalent to 0 in represent a number. The first bit represents the
decimal. sign, the next 8 bits represent the exponent, and
• The value of whole numbers in binary is the remaining 23 bits represent the mantissa (the
represented as 2n−1, where n is the number fractional part).
of bits. Method:
Bytes Number 2n−1 Maximum The method of representing floating-point
of Bits Formula Value numbers using single precision (32-bit) is described
1 Byte 8 2 8− 1 255
16
as follows:
2 Bytes 16 2 −1 65,535
32
1. First, convert the number into binary.
4 Bytes 32 2 −1 4,294,967,295
2. Next, write the number in scientific notation.
2. Integers 3. For a positive number, the sign bit will be 0,
Integers include both positive and negative and for negative number, the sign bit will be 1.
numbers.
4. Calculate the exponent of the number using
• Positive integers are referred to as unsigned
the following formula: 2k-1 -1. In single
integers.
• Negative integers are referred to as signed precision (32-bit), the 8 bits used for
integers. exponent. So, add or subtract exponent from
Example: W = {...,−3,−2,−1,0,1,2,3,...} 127.
Binary Encoding of Integers: 5. Then, convert this exponent into binary.
Since integers include both positive and negative 6. Represent the number according to the 32-bit
numbers, the most significant bit (MSB) is reserved format
as a sign bit: Example 1: Represent 5.75 in single precision 32-
• MSB = 1 → Negative number.
bit floating-point format
• MSB = 0 → Positive number.
Number = 5.75
1. Positive Integers:
The maximum value of a positive integer in Sign = + = 0
memory is represented using 2n−1 − 1, where nn
is the number of bits.
_______________________________________________________________________________________________
3
Example 1: Represent F9.0E in double precision
Binary of the integer part = 5 = 101 64-bit floating-point format.
Binary of the fractional part = 0.75 = 110 Number = F9.0E
5.75 in binary = 101.1102 Sign = + = 0
F9.0E in binary = 11111001.00001110 (2)
Writing in scientific notation: Writing in scientific notation:
101.100 = 1.0111 × 2²
11111001.00001110 = 1.111100100001110 × 2⁷
Exponent = 127 + 2 = 129
Exponent = 1023 + 7 = 1030
Exponent in binary = 129 = 10000001
Exponent in binary = ( 1030 = 1000000110 )
5.75 in single precision 32-bit floating point
F9.0E in double precision 64-bit floating-point
representation:
Sign 8 Bits 23 Bits Mantissa format:
Exponent Sign 11 Bits 52 Bits Mantissa
0 10000001 01110000000000000000000 Exponent
0 01000000110 111100100001110 . . . . 0
(Note: Add bits to the left in the exponent and to
the right in the mantissa by padding with 0s as Binary Arithmetic
necessary.) Binary Arithmetic refers to performing
Example 2: Represent -0.15625 in single precision mathematical operations (such as addition,
32-bit floating-point format. subtraction, multiplication, division, etc.) on binary
numbers.
Number = -0.15625 1. Binary Addition
Sign = - = 1 Binary Addition follows these simple rules:
0+0=0
0+1=1
1+0=1
1 + 1 = 0 (with a carry of 1 to the next bit)
Example: Add binary numbers 1101 and 1011.
1011
-0.15625 in binary = -0.0010102 1101
Writing in scientific notation: -----------------------
-0.001010 = -1.010 × 2⁻³ 11000
Exponent = 127 - 3 = 124 -----------------------
Exponent in binary = 124 = 01111100
-0.15625 in single precision 32-bit floating-point 2. Binary Subtraction
format: Binary subtraction is performed using the 2's
Sign 8 Bits 23 Bits Mantissa complement method. The following procedure is
Exponent adopted to subtract binary numbers using the 2's
1 01111100 01000000000000000000000 complement:
Method:
2. Double Precision (64-Bits)
• Convert both numbers into the binary system.
In this method, 64 bits (8 bytes) are allocated to
represent a number. The first bit represents the • Equalize the number of bits as required.
sign, the next 11 bits represent the exponent, and • Take the 2's complement of the negative
the remaining 52 bits represent the mantissa (the number only. If both numbers are negative,
fractional part). take the 2's complement of both.
Method: • Add the binary representation of the positive
1. First, convert the number into binary. number with the 2's complement of the
2. Next, write the number in scientific notation. negative number. If both numbers are
3. For a positive number, the sign bit will be 0, negative, add their complements.
and for negative number, the sign bit will be 1. • If the sum exceeds the designated number of
4. Calculate the exponent of the number using bits, discard the extra MSB (most significant
the following formula: 2k-1 -1. In double bit).
precision (64-bit), the 11 bits used for • If the MSB of the result is 1 (or if the solution
exponent. So, add or subtract exponent from of both fractional numbers is negative), take
1023. the 2's complement of the result again and add
5. Then, convert this exponent into binary. a negative sign to the answer.
6. Represent the number according to the 32-bit •
format
_______________________________________________________________________________________________
4
Example: Perform 9 - 6 using the binary method.
9 = 1001(2)
6 = 0110(2)
To find the 2's complement of -6, invert all bits of 6
and then add 1 in LSB of inverted bits:
1001
1+
------------------
1010
------------------
-6 = 1010 (2's complement)
Add the binary of the positive number and the
complement of the negative number.
1001
1010+
-------------
10011
Adjust the result if it exceeds the bit size and
discard the MSB (leftmost bit)
i-e 9 – 6 = 0011
3. Binary Multiplication
Binary numbers are base-2 numbers, consisting
only of 0s and 1s. The multiplication of binary
numbers follows similar principles.
Example: Let's multiply two binary numbers: 101₂
and 11₂
101
x11
------
101
101
------
1111
Binary Division
Binary division is similar to decimal division but Encoding Schemes
Encoding schemes convert characters, numbers,
involves only two digits: 0 and 1.
and symbols from various languages into a format
Steps of Binary Division:
that computers can understand and process. Some
Comparison: Compare the divisor with the current
of the popular encoding schemes used in
part of the dividend
computers are:
Subtraction: If the divisor is less than or equal to
the dividend, subtract the divisor from the 1. ASCII (American Standard Code for
dividend. Information Interchange):
Shift: Bring down the next binary digit from the This encoding scheme was established by ISO and
dividend. uses 7 bits to represent 2⁷ = 128 characters. Each
Repeat: Repeat this process until all digits of the character, number, or symbol is assigned a unique
dividend have been used. code between 0 and 127.
Class Activity:
1. Write your name
2. Find the ASCII code for each letter of your
name (refer to the ASCII table for help).
3. Convert each ASCII code into binary format.
_______________________________________________________________________________________________
5
2. Extended ASCII Image File Formats:
This is an 8-bit coding scheme that represents 2⁸, Here are some common formats used for images:
i.e., 256 characters. It has 128 codes for standard JPEG (Joint Photographic Experts Group):
characters, while the remaining 128 codes are used Compresses the image to save space but may lose
to represent graphical and other special characters. some quality.
3. Unicode PNG (Portable Network Graphics):
Among the coding schemes used nowadays, Supports transparency and maintains high quality
Unicode is a popular one. It can represent without losing data.
graphical characters of any language in the GIF (Graphics Interchange Format):
world. Used for simple animations and images with fewer
• Unicode supports various encoding formats, colors.
such as UTF-16, UTF-8, and UTF-32, through 2. Storing Audio
which it can represent over one million In computers, audio files are created by capturing
characters in different languages. UTF stands sound waves and converting them into digital data.
for Unicode Transformation Format. This process is done through sampling and
UTF-8 quantization.
This is a variable-length encoding scheme, Sampling:
meaning it can use different bytes (from 1 to 4) Recording sound waves at regular intervals is called
to represent characters. UTF-8 is compatible sampling. The number of samples taken per second
with ASCII, which means it can understand and is called the sampling rate. Higher sampling rates
use the old ASCII encoding scheme without any provide better quality.
issue. Hence, if we have a text file written in Quantization:
ASCII, it will work perfectly fine with UTF-8. Converting each sample into a number. More bits
UTF-16
per sample result in better sound quality.
This is also a variable-length encoding scheme. It
Audio File Formats:
uses 2 or 4 bytes to represent characters. Unlike
MP3:
UTF-8, it is not compatible with ASCII, which
means it cannot translate ASCII codes. A common format that compresses audio to save
UTF-32 space but may lose some quality.
UTF-32 is a fixed-length encoding method, where WAV (Wave Audio File Format):
all characters are stored using 4 bytes per An uncompressed format that maintains high
character. quality.
AAC (Advanced Audio Coding):
Memory Units Used by many streaming services to provide high-
Data is stored in memory in the form of bytes, and quality audio with efficient compression.
the different units for measurement of memory are 3. Storing Videos
as follows: Videos consist of multiple images shown in a fast
Large Unit Symbol Smaller Unit sequence, along with audio. Each image in a video
(Large Unit) is called a frame.
1 Byte B 8 Bits Frame Rate:
1 Kilobyte KB 1024 Bytes The number of frames shown per second is called
1 Megabyte MB 1024 Kilobytes the frame rate. Common frame rates are 24 fps
1 Gigabyte GB 1024 Megabytes (used in movies) and 30 fps (used in TV shows).
1 Terabyte TB 1024 Gigabytes
Video File Formats:
1 Petabyte PB 1024 Terabytes MP4:
1 Exabyte EB 1024 Petabytes
A widely used format that compresses video
1 Zettabyte ZB 1024 Exabytes
efficiently while maintaining quality.
1 Yottabyte YB 1024 Zettabytes
AVI:
How are Images, Audio, and Videos Stored An older format that can result in larger file sizes.
in Computers? MKV:
1. Storing Images Supports high-quality video and multiple audio
Images are made up of tiny dots called pixels. Each tracks or subtitles.
pixel has a color, and these pixels together form a How are these files stored in computers?
complete image. All these files (images, audio, and video) are stored
The color of each pixel can be represented by three as binary data, which means they are represented
numbers: red, green, and blue (RGB). Each number using 0s and 1s.
typically ranges from 0 to 255. For example, (255, Storage Devices
0, 0) represents bright red. Computers use these Hard Disk Drive (HDD):
numbers to represent the colors of an image. Uses spinning disks to read/write data. It provides a
large storage capacity.
_______________________________________________________________________________________________
6
Solid-State Drive (SSD):
Uses flash memory for faster access times and
better performance.
Cloud Storage:
Stores files on remote servers that are accessible
via the internet and are commonly used for
backups.
Difference between ASCII and Unicode
ASCII Unicode
Each character in ASCII is Different forms of
represented using 7 or 8 Unicode can represent
bits characters using 1 to 4
bytes
ASCII was created to Unicode was developed
represent English to represent characters
characters and symbols from almost
all languages worldwide
ASCII is mostly used in Unicode is used in
simple and text-based modern systems and
systems applications
_______________________________________________________________________________________________
7