Unit 2: Number Systems — Long Questions
9th Class Computer Science · Unit 2: Number Systems
Ans. Numbering systems are essential in computing because they form the basis for representing, storing and processing data. Different numbering systems help computers perform tasks like calculations, data storage, and data transfer. Here is a description of a few numbering systems that are used most frequently:
1. Decimal System
The decimal numbering system is a base-10 number system that uses digits from 0 to 9 and we use it in our daily life. Each digit represents a power of 10 in decimal, the place values from right to left are 10⁰, 10¹, 10², and so on. For example, The decimal number 523 means:
5x10²+2x10¹+3x10⁰=500+20+3=523
2. Binary System
The binary numbering system is a base-2 number system that uses digits from 0 to 1. Each digit represents a power of 2 In binary, the place values from right to left are 2⁰,2¹,2², and so on. For example, The binary 1011 means:
1×2³+0×2²+1×2¹+1×2⁰=8+0+2+1=11₁₀
Conversion from Decimal to Binary
The following algorithm converts a decimal number to binary.
• Divide the decimal number by 2.
• Record the remainder.
• Repeat the division by 2 until the quotient is 0.
• The binary number is the remainders read from bottom to top.
Example Convert 83 to binary
83 / 2 =41 remainder 1
41 / 2 =20 remainder1
20 / 2 =10 remainder 0
10 / 2 =5 remainder 0
5 / 2 =2 remainder 1
2 / 2 =1 remainder 0
1 / 2 =0 remainder 1
OR
2 | 83
2 | 41 – 1
2 | 20 – 1
2 | 10 – 0
2 | 5 – 0
2 | 2 – 1
2 | 1 – 0
| 0 – 1
Decimal to Binary Conversion
3. Octal System
The octal numbering system is a base-8 number system that uses digits from 0 to 7 Each digit Represents a power of 8. In octal, the place values from right to left are 8⁰,8¹,8², and so on. For example, the octal 157 means:
1×8²+5×8¹+7×8⁰=64+40+7=111₁₀
Each octal digit represents three binary digits (bits)because the octal system is base-8, and the binary system is base-2. This relationship arises from the fact that 8 is a power of 2(8=2³).So, each over all digit can be precisely represented by three binary digits (bits).
Example
Consider the 9- bit binary number 110101011. This number can be divided into group of three. Bits from right to left:
110 101 011
Each group of three bits corresponds to a single octal digit:
110=6
101=5
011=3
So, the binary numbers 110101011 is equivalent to the octal number 653.
Conversion from Decimal to Octal
The following algorithm converts a decimal number to octal.
1. Divide the decimal number by 8.
2. Write down the remainder.
3. Divide the quotient ·by 8.
4. Repeat until the quotient is 0.
5. The octal number is the remainders read from bottom to top:
Example Convert 83 to octal
• 83/8=10 remainder 3
• 10/8=1 remainder 2
• 1/ 8=0 remainder 1
OR
8 | 83
8 | 10 – 3
8 | 1 – 2
| 0 – 1
Decimal to Octal
So, 83₈ = 123₁₀
Ans. The hexadecimal numbering system is a base-16 number system that uses digits from 0 to 9 and letters from A to F Each digit represents a power of 16. The letters A to F represent the values 10 to 15 respectively as shown in Table. In hexadecimal, the place values from right to left are 16⁰,16¹,16², and so on. For Example, the hexadecimal number 1A3 means:
1×16²+A×16¹+3×16⁰=1×256+10×16+3×1=256+160+3=419₁₀
Each hexadecimal digit represents four binary digits (bits) because the hexadecimal system is base-16 and the binary system is base-2. This relationship arises from the fact that 16 is a power of 2 (16=2⁴). This means that any value from 0 to 15 in hexadecimal can be converted into a 4-bit binary number. This relationship makes conversion between binary and hexadecimal. Table shows the correspondence between hexadecimal and binary digits:
Example Consider the 16-bit binary number 1101011010110010.This number can be divided into group of four bits from right to left:
1101 0110 1011 0010
1101=D
0110=6
1011=B
0010=2
Converting Decimal to Hexadecimal
The following algorithm converts a decimal number to hexadecimal:
1. Convert the decimal number to an absolute value by dividing it by 16.
2. Record the qudtient and the remainder.
3. Continue dividing the quotient by 16 and write down the remainder until the quotient is zero.
4. The hexadecimal number, as you might have guessed, is the remainder read from bottom to top.
Example Convert 2297 to hexadecimal
2297 /16=143 remainder 9
143/16=8 remainder F
8 /16=0 remainder 8
OR
16 | 2297
16 | 143 –→9
16 | 8 – 15 –→F
| 0 – 8 –→8
Decimal to Hexadecimal
Ans Computers are amazing machines that can process and store a lot of information. In the following section we will see numeric data representation.
Binary Encoding of Integers(Z) and Real Numbers(R)
When we store data in computers especially numbers, it's important to understand how they are represented and stored in memory. Let's explore how different size of integer values are stored in 1, 2 and 4 bytes and how we can store positive and negative integers.
Whole Numbers (W) and Integers(Z)
Integers, also known as whole numbers, are important elements in both mathematics and computer science. Knowledge of these concepts is important for primary computations, solving problems through programming, working with data and designing algorithms.
Whole Number (W)
Whole numbers are the set of non-negative numbers. They include zero and all the positive integers. Mathematically, the set of whole numbers is:
W={0, 1, 2, 3, … …}
In computing, whole numbers are often used to represent quantities that can't be negative. Examples include the number of students in a school, a person's age in years, and grades, provided there are no negative figures such as a credit point balances.
1-byte integer has 8 bits to store values. If all 8 bits are ON, it represents the maximum value, 11111111₂ which is 255₁₀. If all bits are OFF, it represents the minimum value 00000000₂, which is 0₁₀. If n is the number of bits, the maximum value we can represent is 2ⁿ -1. For example,
• 1-Byte whole number (8 bits): Maximum value=2⁸-1=255
• 2-Byte whole number (16 bits): Maximum value=2¹⁶-1=65,535
• 4- Byte whole number (32 bits): Maximum value=2³²-1=4,294,967,295
Integers(Z)
Integers extend the concept of whole numbers to include negative numbers. In the world of computer programming. We call them signed integers. The set of integers is represented as:
Z={…..,-3, -2, -1,0,1,2,3……}
To store both positive and negative values, one bit is reserved as the sign bit (the most significant bit).
Negative Values and Two's Complement
In order to store negative values. Computers use a method called two's complement. To find the two's complement of a binary number, follow these steps:
1. Invert all the bits (change 0s to 1s and 1s to 0s).
2. Add 1 to the least significant bit(LSB).
Example Let's convert the decimal number -5 to an 8 bit binary number:
1. Start with the binary representation of 5:00000101₂.
2. Invert all the bits: 11110110₂.
3. Add 1: 11110110₂+1₂=11111011₂.
So, -5 in 8-bit two's complement is 11111011₂.
Minimum Integer Value
For 8-bit integer, we switch on the sign bit for the negative value and make all bit ON which results 11111111₂. Except the first bit, we take two's complement and get 10000000₂. Which is 128₁₀. So the minimum value in 1- byte integer is -128 , i.e., -2⁷ . So, the minimum value is computed using the formula -2ⁿ, where n is the total number of bits.
• 2-Byte Integer (16 bits): Minimum value=-2¹⁵ = -32,768
• 4-Byte Integer (32 bits): Minimum value= -2³¹-1= -2,147,483,648
Ans In computers, real values (also known as floating- point numbers) are used to represent numbers that have fractions or decimal points.
Understanding Floating Point Representation
Floating-point numbers (real values ) are represented in a way similar to scientific notation given below:
Floating –point number =sign x mantissa x 2ˣᵖᵒⁿᵉⁿᵗ. According to the above formula, 5.75 is represented as 1.4375 x 2.
Step for Conversion
1. Identify the Fractional Part: Extract the fractional part of the decimal number. For example. If the number is 4.625, the integral part is 4 and the fractional part is 0.625.
2. Convert the Fractional part to Binary: Multiply the fractional part by 2 and record the integer part of the result. Continue this process with the new fractional part until it becomes 0 or until you reach the desired precision.
Example Converting 0.375 to Binary
1. Identify the Fractional Part: Fractional part:0.375
2. Convert the Fractional Part: 0.375 to Binary.
0.375 ×2=0.75 ( Integer part:0)
0.75×2=1.5 ( Integer part:1)
0.5×2=1.0 ( Integer part:1)
The integer parts recorded are 0,1,1
3. Combine the Results:- Combine the binary representations of the integer parts from top to bottom:
0.375₁₀=0.011₂
In computer science, representing real numbers in binary form is essential for efficient computation and storage. This process involves converting both the integer (decimal) and fractional parts of as number into binary. The two most commonly used standard are "single precision (32-bits) and Double Precision (64-bit)"
Ans Single Precision (32-bit)
In this standard, 4 bytes (32 bits) are used where 1 bit is for the sign, next 8 bits for the exponent and the last 23 bits for the mantissa.
• The exponent ranges from -126 to +127.
• The approximate range of values: 1.4×10⁻⁴⁵ to 3.4×10³⁸.
Explanation
Table illustrates how 32 bits floating point values are represented in binary form. Each floating point value is broken down into three main components. The sign bit, the exponent, and mantissa.
Grouping This row explains the bit allocation for the 32-bit floating point format: 1 bit for the sign, 8 bits for exponent, and 23 bits for the mantissa.
1. 5.75: Representation: 1.4375x2²- sign Bit: 0(positive)-Exponent: 2+127=129, which is 10000001₂. Mantissa: the binary representation of 0.4375 is 10111000000000000000000₂.
2. -5.75: Representation: -1.4375x2²-Sign Bit:1(negative) -Exponent:2 +127=129. which is 10000001₂. Mantissa: The binary representation of 0.4375 is 10111000000000000000000₂.
3. 0.15625: Representation:1.25x2⁻³ -Sign bit:0 (positive)-Exponent: -3+127=124, which is 01111101₂. Mantissa: The binary representation of 0.25 is 01000000000000000000000₂.
4. -0.15625: -Representation: -1.25x2⁻³ Sign bit:1 (negative) Exponent: -3+127=124, Which is 01111101₂. Mantissa: The binary representation of 0.25 is 01000000000000000000₂. This breakdown help illustrates how floating-point values are stored and manipulated in computer systems.
Double Precision (64-bit)
In double precision, the exponents is represented using 11 bits. The exponent is stored in a biased form with a bias of 1023. The range of the actual exponent values can be determined as as follows:
• Bias:1023
• Exponent range: The actual exponent values range from -1022 to +1023. Therefore, the smallest and largest possible exponent values in double precision are:
• Minimum exponent: -1022
• Maximum exponent: +1023
Ans. Binary Arithmetic refers to the operations of addition, subtraction, multiplication, and division performed on binary numbers. Binary arithmetic operations are similar to decimal operations but follow binary rules. Here's a brief overview of basic operations:
1. Addition
Binary addition uses only two digits: 0 and 1 Here, we will learn how to add binary numbers and also how to handle the addition of negative binary numbers.
Binary Addition Rules
Binary addition follows these simple rules:
1. 0+0=0
2. 0+1=1
3. 1+0=1
4. 1+1=0 (with a carry of 1 to the next higher bit)
Example of Binary Addition
Example
1101
+1011
______
01100 = 24 (Decimal)
In this example
• 1+1=0 (carry1)
• 0+1+1 (carry)= 0 (carry 1)
• 1+0+1(carry) =0 (carry 1)
• 1+1+1 (carry)= 1 (carry 1)
2. Subtraction
In binary arithmetic, subtraction can be performed by adding the two's complement of the subtrahend (the number being subtracted) to the minuend (the number from which another number is subtracted).
Example Substract 6 from 9 in Binary
Minuend =9₁₀=1001₂
Subtrahend =6₁₀=0110₂
Step 1 Find the Two's Complement of the Subtrahend
• Invert the bits of 0110₂.
Inversion: 1001₂
• Add 1 to the inverted number:
1001₂+1₂=1010₂ = -6₁₀
Step 2 Add the Minuend and the Two's Complement of the subtrahend
1001₂+1010₂=10011₂
Step 3 Discard the Carry Out
10011₂→Discard carry →0011₂ =3₁₀
So, 9-6=3.
3. Multiplication
Binary numbers are base-2 numbers. Consisting of only 0s and 1s. Multiplying binary numbers following similar principles to multiplying decimal numbers, but with simpler rules. Here, we will learn how to multiply binary numbers with example and practice questions.
Step to Multiply Binary Numbers
1. Write down the binary numbers, aligning them by the least significant bit (rightmost bit).
2. Multiply each bit of the second numbers by each bit of the first numbers, similar to the long multiplication method in decimal.
3. Shift the partial results one place to the left for each new row, starting from the second row.
4. Add all the partial results to get the final product.
Example
Let's multiply two binary numbers: 101₂ and 11₂.
1 0 1
× 1 1
______
1 0 1 (This is 101₂ x 1₂)
1 0 1 × 0 (This is 101₂ x 1₂, Shifted left)
1 1 1 1
So, 101₂ x 11₂ =1111₂
4. Division
Binary division is similar to decimal division but only involves two digits, 0 and 1. Binary division includes steps like comparing, subtracting, and shifting. Akin to long division in the decimal system.
Steps of Binary Division
1. Compare: Compare the divisor with the current dividend portion.
2. Subtract: Subtract the divisor from the dividend portion if the divisor less than or equal to the dividend.
3. Shift: Shift the next binary digit from the dividend down to the remainder.
4. Repeat: Repeat the process until all digits of the dividend have been used.
Example
Divide 1100₂ by 10₂
110
10 1100
10 (Step 1: Compare 10 with first two digits 11, Subtract 10 from 11)
10 (Step 2: Bring down the next digit 0)
–10 (Step 3: Compare 10 with 10, subtract 10 from 10)
0 (Step 4: Bring down the next digit 0, no more digits left)
Result 1100₂ / 10₂= 110₂ / 10₂= 110₂
Ans. Text encoding schemes are essential for representing characters from various languages and symbols in a format that computers can understand and process. Here are some of the most common text encoding schemes used in computers:
1. ASCII
ASCII stands for American Standard Code for information Interchange. It is character encoding standard used to represent text in computers and other devices that use text. Each letter, digit, or symbol is assigned a unique number between 0 and 127, as shown in Table. The ASCII code for 'P' is 80.
The ASCII code for 'a' is 97.
The ASCII code for 'k' is 107.
The ASCII code for 'i' is 105.
The ASCII code for 's' is 115.
The ASCII code for 't' is 116.
The ASCII code is a numerical representation of characters in computer-based system, particularly for alphabetic characters. For example, the ASCII code of the character 'n' is 110.
Extended ASCII
While the standard ASCII table includes 128 characters, there is an extended version that includes 256 characters. This extended ASCII uses 8 bits and includes additional symbols, accented letters, and other characters. However, the original 128 characters are the most commonly used and are the basis for text representation in computers.
2. Unicode
Unicode is a character encoding standard that aims to cover all the characters used in the world's writing systems. Unlike ASCII, which only uses 7 bits and can represent 128 characters. Unicode uses 7 bits and can represent over a million characters using different encoding forms like UTF-8, UTF-16, and UTF-32 UTF stands for Unicode Transformation Format.
UTF-8
It is a variable-length encoding scheme, which means it can use different numbers of bytes (from1 to 4) represent a character. UTF-8 is backward compatible with ASCII. It means that UTF-8 can understand and use the older ASCII encoding scheme without any problems. So, if we have a text file written in ASCII, it will work perfectly fine with UTF-8. It's like being able to read both old and new books.
Example The letters 'A' is Unicode (which is U+0041) is represented as 01000001 in binary form and occupies 8 bits or 1 byte.
Let's look at how Urdu letters are represented in UTF-8:
Example The letter 'ط' (which is U+0628 in Unicode) is represented as 11011000101010000 in binary (2 bytes).
UTF-16
UTF-16 is another variable-length encoding scheme, but it uses 2 or 4 bytes for each character. Unlike UTF-8, it is not backward compatible with ASCII
Example The letter A is represented as 00000000 01000001 in binary (2 bytes).
For Urdu
Example The Urdu letter 'ط' is represented as 00000110 00101000 in binary (2 bytes).
UTF-32
UTF-32 is a fixed -length encoding scheme. Every character, no matter what, is represented using 4 bytes. This makes it very simple, but at the same time it may look a little complicated when it comes to space usage.
Example The letter A is represented as 00000000 00000000 00000000 01000001 in binary (4 bytes).
Ans. UTF-8
It is a variable-length encoding scheme, which means it can use different numbers of bytes (from1 to 4) represent a character. UTF-8 is backward compatible with ASCII. It means that UTF-8 can understand and use the older ASCII encoding scheme without any problems. So, if we have a text file written in ASCII, it will work perfectly fine with UTF-8. It's like being able to read both old and new books.
Example The letters 'A' is Unicode (which is U+0041) is represented as 01000001 in binary form and occupies 8 bits or 1 byte.
Let's look at how Urdu letters are represented in UTF-8:
Example The letter 'ط' (which is U+0628 in Unicode) is represented as 11011000101010000 in binary (2 bytes).
UTF-16
UTF-16 is another variable-length encoding scheme, but it uses 2 or 4 bytes for each character. Unlike UTF-8, it is not backward compatible with ASCII
Example The letter A is represented as 00000000 01000001 in binary (2 bytes).
For Urdu
Example The Urdu letter 'ط' is represented as 00000110 00010100 in binary (2 bytes).
UTF-32
UTF-32 is a fixed -length encoding scheme. Every character, no matter what, is represented using 4 bytes. This makes it very simple, but at the same time it may look a little complicated when it comes to space usage.
Example The letter A is represented as 00000000 00000000 00000000 01000001 in binary (4 bytes).
Ans Have you ever wondered how your favorite photos, songs, and movies are stored on your computer or phone? Let's dive into the fascinating world of digital storage to understand how computers manage these different types of files.
1. Storing Images
Images are made up of tiny dots called pixels. Each pixel has a color, and the combination of all these pixels forms the complete picture. Computers store images using numbers to represent these colors.
• Color Representation: In a color image each pixel's color can be represented by three numbers: Red, Green, and Blue (RGB). Each of these numbers typically ranges from 0 to 255. For Example, a pixel with RGB values (255,0,0) will be bright red.
• Image File Formats: JPEG (Joint Photographic Expert Group): Common format for photos. It compresses the image to save space but might lose some quality.
• PNG (Portable Network Graphics): Supports transparency and maintains high quality without losing data.
• GIF (Graphics Interchange Format): Used for simple animations and images with few colors.
2. Storing Audio
Audio files are stored by capturing sound waves and converting them into digital data. This process involves sampling and quantization.
• Sampling: Recording the sound wave at regular intervals. The number of samples per second is called the sampling rate. Higher sampling rates means better quality.
• Quantization: Converting each sample into a number. More bits per sample mean more accurate sound representation.
Audio file Formats
• MP3: A common format that compresses audio to save space but may lose some quality.
• WAV (Wave Audio File Format): Uncompressed format that maintains high quality.
• AAC (Advanced Audio Coding): Used by many streaming services for high- quality audio with efficient compression.
Examples To illustrate how these units are used, consider the following example:
• An image file might have a size of 500 KB (Kilobytes).
• A music file might be around 5MB (Megabytes).
• A full-length HD movie could be approximately 2 GB (Gigabytes).
• A large external hard drive could have a capacity of 1 TB (Terabytes).
3. Storing Video
Videos are made up of many images shown rapidly one after another, along with audio. Each image in a video is called a frame.
Frames and Frame Rate
• Frame Rate: The number of frames shown per second, measured in Frames Per Second (FPS). Common frame rates are 24 fps (use in movies) and 30 fps (used in TV). Higher frame rates result in smoother motion in videos.
Video File Formats
• MP4: Widely used format that efficiently compresses video while maintaining quality.
• AVI: Older format that may result in large file sizes.
• MKV: Supports high- quality video and multiple audio tracks/ subtitles.
How Computers Store These Files?
All these files (images, audio, and video) are Binary data, which means they are represented by sequences of 0s and 1s.
Storage Devices
• Hard Drives (HDD): Uses spinning disks to read/write data. They offer large storage capacities.
• Solid State Drives (SSD): Use flash memory for faster access times and better performance.
• Cloud Storage: Storage files on remote servers accessible via internet, providing flexibility and backup.