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

chap 2 computer

Chapter 2 discusses various number systems including decimal, binary, octal, and hexadecimal, explaining their bases and how they represent data. It details algorithms for converting between these systems and covers concepts such as bits, bytes, signed and unsigned integers, and floating-point representation. The chapter also addresses how computers store and process these values, particularly focusing on the two's complement method for negative numbers and the structure of floating-point numbers.

Uploaded by

Maryam Majeed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

chap 2 computer

Chapter 2 discusses various number systems including decimal, binary, octal, and hexadecimal, explaining their bases and how they represent data. It details algorithms for converting between these systems and covers concepts such as bits, bytes, signed and unsigned integers, and floating-point representation. The chapter also addresses how computers store and process these values, particularly focusing on the two's complement method for negative numbers and the structure of floating-point numbers.

Uploaded by

Maryam Majeed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Chapter 2: Number System

Q1: What is a number system?

Ans: A number system is a way to represent numbers using a set of


symbols and rules. In computing, number systems represent, store, and
process data. Different number systems include:

 Decimal system (Base-10): Uses digits 0–9; used in daily life.

 Binary system (Base-2): Uses digits 0 and 1; used by computers.

 Octal system (Base-8): Uses digits 0–7; each digit equals 3 binary
bits.

 Hexadecimal system (Base-16): Uses digits 0–9 and letters A–F.

Q2: Define the Decimal system.

Ans: The decimal number system is a base-10 number system that consists
of digits from 0 to 9, and we use it in everyday life. That's why each digit of
the number represents a power of 10, e.g., 829

Q3: Define a Binary system.

Ans: Binary is a base-2 number system that comprises only digits 0 and 1.

Each digit represents the power of 2. e.g., 10011.

Q4: Explain why computers use the binary number system and how
different types of data are represented using it.

Ans: Computers work in a binary system, especially because this method fits
well with electronics. Digital circuits have two states: They can be either on
or off. These states are easily represented by the binary digits: 1 represents
ON, and 0 represents OFF. When typing on the keyboard, the computer
translates every letter into a binary. Similarly, number, text, images, and
sound are all, at their lowest level, reduced to binary.

Q5: How can a decimal number be converted into binary? Describe


the algorithm

Ans: The following algorithm converts a decimal number to binary.

1. To convert a decimal number to binary form, divide the decimal number


by 2.

2. Record the remainder.


3. Divide the number by 2 until the quotient, which is left after division, is 0.

4. Meaning it is represented by the remainders and it's read from the bottom
to the top of the binary number.

Example: Convert 83 to binary

83 / 2 = 41 remainder 1

41 / 2 = 20 remainder 1

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

If the remainders are read from bottom to top, it gives the required result in
binary, 1010011.

Q6: Define an Octal Number System.

Ans: The Octal number system is another number system that has eight (8)
as its base; thus, it has eight digits, 0 to 7. Each digit represents a power of
8, this can be expressed as 8-digit

Q7: Why is each digit in the octal number system represented by


precisely three bits?

Ans: Each octal digit represents three binary digits (bits) because the octal
system is base-8, while the binary system is base-2. This relationship arises
from the fact that 8 is a power of 2, specifically, 8 = 2^3 As a result, each
octal digit can be precisely represented by a group of three binary bits.

Q8: How can a decimal number be converted into Octal? Describe


the algorithm

Ans: The algorithm converts a decimal number into an octal.

1. To convert the decimal number to an equivalent octal number, divide the


number by 8.
2. Write down the remainder.

3. After that, divide the obtained quotient by 8.

4. Continue the divisions until one of the numbers results in 0.

5. Octal is a base-eight number, and the octal number is the remainder read
from the bottom up to the top.

Example: Convert 83 to octal

• 83 / 8 = 10 remainder 3

• 10 / 8 = 1 remainder 2

• 1 / 8 = 0 remainder 1

Now 123 is in the octal system.

Q9: Define the Hexadecimal Number System.

Ans: The Hexadecimal numbering system is another type of number system


with a base of 16, where the numbers 0 to 9 and the letters A-F are used.

Q10: Why is each digit in the Hexadecimal number system


represented by precisely four bits?

Ans: Each hexadecimal digit represents four binary digits (bits) because the
hexadecimal system is base-16, and the binary system is base-2. This means
every single hexadecimal digit is equal to a 4-bit binary value. This
relationship exists because 16 is a power of 2 — specifically, 16=2^4.
Therefore, any hexadecimal number from 0 to 15 can be directly converted
into a 4-bit binary number.

Q11: How can a decimal number be converted into hexadecimal?


Describe the algorithm.

Ans: 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 quotient 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

Now 8F9 is in hexadecimal.

Q12: Define whole numbers.

Ans: Whole numbers are a set of non-negative integers. They include zero
and all the positive integers. Mathematically, the set of whole numbers is: W
= {0,1,2, 3,...}.

Q13: Define integer numbers.

Ans: Integers extend the concept of whole numbers to include negative


numbers. In computer programming, we call them signed integers. The set of
integers is represented as: Z = {..., -3, -2,-1,0,1,2, 3,...}.

There are mainly two types of integers based on how they store values:

Signed integer: Signed integers can represent both positive and negative
numbers.

Unsigned integer: Unsigned integers can only represent non-negative


numbers (0 and positive numbers).

Q14: Define a Bit.

Ans: A bit is the smallest piece of data a computer uses.


It can only be a 0 or a 1, like a light switch that is either off (0) or on (1).

Q15: Define a Byte.


Ans: A byte is a group of 8 bits. It’s used to store information in a computer,
like a letter, a number, or a symbol.
For example, letter A is stored as 1 byte in memory.

Q16: What are the maximum and minimum values represented in a


Byte?

Ans: A 1-byte integer has 8 bits to store a value.

 If all 8 bits are 1 (like this: 11111111), it shows the maximum value,
which is 255.

 If all bits are 0 (like this: 00000000), it shows the minimum value,
which is 0.

This is how computers use bits to count and store numbers.

Q17: What is the formula for calculating the maximum value of an


unsigned integer with n bits, and what are the maximum values for
1,2,3 byte integers?

Ans: The formula to calculate the maximum value for an unsigned integer
with n bits is:

2n-1.

 1-byte (8 bits): Maximum value = 28 −1=255.

 2-byte (16 bits): Maximum value =216-1=65,535.

 4-byte (32 bits): Maximum value = 232-1=4,294,967,295.

Q18: How are signed integers stored in computer memory, and what
is the formula for calculating the maximum positive value in an n-bit
signed integer?

Ans: When storing both positive and negative values in an integer, one bit is
used as the sign bit (usually the most significant bit, or MSB).

 If the sign bit is 1, the number is negative.

 If the sign bit is 0, the number is positive.

Example (1-byte signed integer):

 8 bits (1 byte) are used for storing the value. The first bit is the sign
bit.

 The remaining 7 bits are used to store the value.


 The maximum positive value that can be stored is when the sign bit is
0 and the rest of the bits are all 1 (i.e., 01111111), which equals 127.

This is because with 7 bits left for the value, the maximum you can represent
is 27−1=127.

General Formula for Maximum Signed Value:

For an n-bit signed integer, the maximum positive value can be calculated
as:

2(n−1)-1

Examples:

 1-byte (8 bits): Maximum positive value = 2(8−1)−1=127.

 2-byte (16 bits): Maximum positive value = 2 (16−1)−1=32,767.

 4-byte (32 bits): Maximum positive value = 2 (32−1)−1=2,147,483,647.

Q19: How do Computers Store Negative Values in computer


Memory?

Ans: To store negative values, computers use a method called two's


complement.

Steps to Find the Two's Complement:

1. Invert all bits (change 0s to 1s, and 1s to 0s).

2. Add 1 to the Least Significant Bit (LSB).

Example: Convert -5 to 8-bit Binary

1. Start with the binary of +5: 00000101 (in binary)

2. Invert all bits (1's complement): 11111010.

3. Add 1 (to get 2's complement): 11111010 + 1 = 11111011.

-5 in 8-bit two's complement is 11111011₂.

Q20: Explain how the minimum value for an 8-bit signed integer is
calculated using two’s complement.

Ans: For an 8-bit signed integer (1 byte):

 An 8-bit number has values from 0 to 255 in unsigned form.

 In two’s complement, the most significant bit (MSB) is the sign bit:
o 0 = positive

o 1 = negative

To find the minimum value:

1. Turn ON the sign bit and set all other bits OFF:
Binary: 10000000

2. This represents the value: -27=128

Minimum value (8-bit signed integer) = -128

For a 16-bit signed integer (2 bytes):

 Use the same formula: Minimum value=-2n-1

Where n=16: −215=−32,768

For a 32-bit signed integer (4 bytes):

 Use the same formula: Minimum value=-2n-1

Where n=32: −231=−2,147,483,648

Q21: Define real values?

Ans: In computers, real values, also known as floating-point numbers,


represent numbers with fractions and/or decimals.

Q22: Explain how floating-point numbers are represented in a


computer?

Ans: Floating-point numbers (real values) are represented in computers


using a format similar to scientific notation. The general structure is:

Floating-point number=sign×mantissa×2exponent

Example:

For example, the decimal number 5.75 is represented as:

5.75=1.4375×22

Q23: Describe the process for converting the fractional part of a


decimal number to binary.

Ans: To convert the fractional part of a real number from decimal (base-10)
to binary

(base-2):
1. Multiply the fractional part by 2

2. Write down the integer part (0 or 1)

3. Repeat the process with the new fractional part

4. Stop when the fractional part becomes 0 or when the required


precision is reached

Example: Converting 4.625 to Binary

Step 1: Convert Integer Part (4)

4 ÷ 2 = 2 → remainder 0
2 ÷ 2 = 1 → remainder 0
1 ÷ 2 = 0 → remainder 1

Binary: 100

Step 2: Convert Fractional Part (0.625)

 0.625 × 2 = 1.25 → 1

 0.25 × 2 = 0.5 → 0

 0.5 × 2 = 1.0 → 1

Binary: .101

Final Binary Result:

4.625₁₀ = 100.101₂

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 x 2 = 0.75 (Integer part: 0)

0.75 x 2 = 1.5 (Integer part: 1)

0.5 x 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 10 2

Q24: what are the two commonly used standards for binary
representation of real numbers?

Ans: The two commonly used standards for binary representation of real
numbers in computing are

 Single Precision (32-bit)


 Double Precision (64-bit).

These standards define the format for floating-point numbers used in


computers.

Q25: How are the 32 bits organized in the standard for representing
single-precision floating-point numbers?

Ans: In this standard, 4 bytes (or 32 bits) are assigned where the 1st bit is
the sign bit, and the next 8 bits are for the exponent, and the remaining 23
bits are for the mantissa.

What is the purpose of the sign bit in the floating-point representation?

The sign bit determines whether the number is positive or negative.

 If the sign bit is 0, the number is positive.

 If the sign bit is 1, the number is negative.

How is the exponent stored and interpreted in a single precision


format?
The exponent is stored using a method called "biased exponent".

 In the single-precision (32-bit) format, the exponent is 8 bits long.

 It uses a bias of 127, meaning the actual exponent value is calculated


as:

Actual exponent=Stored exponent−127

This allows for both positive and negative exponents.


What is the role of the mantissa, and how does it affect the
precision of the number?
Ans: The mantissa holds the actual digits of the number (after the decimal).
It decides how accurate or precise the number is.
The more detail in the mantissa, the more exact the number.

Q: What is the range of exponents and value range in single precision?

 The exponent ranges between 126 and +127 for single precision.
 The approximate range of values from 1.4 x 10-45 to 3.4 x 1038

Steps

Decimal number: 5.75

Step 1: Convert to binary

5 = 101 5/2=2 remainder1


0.75 = 0.11
2/2-1 remainder 0
0.75 x 2= 1.5 integral 1 1/2=0 remainder 1
0.5 x 2 = 1.0 integral 1 5=101

As a fraction remains 0 stop it

So, 5.75 in binary = 101.11

Step 2: Normalize the binary

We write 101.11 as: 1.0111 × 2²

Representation in scientific notation: 1.0111 (binary) means:

 The first digit 1 is 1 × 2⁰ = 1

 The second digit 0 is 0 × 2⁻¹ = 0

 The third digit 1 is 1 × 2⁻² = 0.25

 The fourth digit 1 is 1 × 2⁻³ = 0.125

 The fifth digit 1 is 1 × 2⁻⁴ = 0.0625

Now, we add up all these values:

1+0+0.25+0.125+0.0625=1.43751 =>1.4375 x22


Step 3: Sign bit

Since 5.75 is positive, the sign bit = 0

Step 4: Exponent

Exponent = 2
In single precision, we add a bias of 127
So:
2 + 127 = 129
129 in binary = 10000001

Step 5: Mantissa (23 bits)

We take the digits after the binary point in 1.0111, which are:
01110000000000000000000 (fill with 0s to make 23 bits).

Q25: How are the 64 bits organized in the standard for representing
Double-precision floating-point numbers?

Ans:

Q26: What is the range of exponents and value range in Double


precision?

In double precision, the exponent 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 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

Define a Binary Arithmetic operation:


Arithmetic operations mean addition, subtraction, multiplication, and division
performed on numbers in the given base. Binary arithmetic involves
performing these operations on numbers in binary form, or base 2.

How to add two binary numbers?

Binary addition uses only two digits: 0 and 1.

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 1:

1101

+1011

11000

In this example:

• 1 + 1 = 0 (carry 1)

• 0 + 1 + 1 (carry) = 0 (carry 1)

• 1 + 0 + 1 (carry) = 0 (carry 1)

• 1 + 1 + 1 (carry) = 1 (carry 1)

How to subtract two binary numbers?

Ans: In binary arithmetic, subtraction can also be carried out by adding the
two’s

complement or the value of the subtrahend to the minuend.

Example: Subtract 6 from 9 in Binary

Minuend = 9 = 1001 102


Subtrahend = 6 = 0110 10 2

Step 1: Find the Two's Complement of the Subtrahend

• Invert the bits of 0110 2

Inversion: 10012

• Add 1 to the inverted number:

10012 + 12 = 10102 = -610

Step 2: Add the Minuend and the Two's Complement of the


Subtrahend

10012 +10102 = 100112

Step 3: Discard the Carry Bit

100112 Discard carry 00112 = 310

So, 9 - 6 = 3.

How to multiply two binary numbers?

Ans: Binary numbers are base-2, consisting of only 0s and 1s.

Steps 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 number by each bit of the first number,
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: 1012 and 112

How to divide two binary numbers?


Ans: Binary division is similar to decimal division but only involves two
digits: 0 and 1.

Steps of Binary Division

1. Compare: Compare the divisor with the current portion of the dividend.

2. Subtract: Subtract the divisor from the dividend portion if the divisor is
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 dividend digits have been used.

Example: Divide 1100₂ by 10₂

Step 1: Compare 10 with the first two digits (11),


subtract 10 from 11
Step 2: Bring down the next digit (0)
Step 3: Compare 10 with 10, subtract 10 from 10
Step 4: Bring down the next digit (0), no more
digits left

Result: 1100₂ ÷ 10₂ = 110₂

What are Text Encoding Schemes? Write its types.

Ans: Text encoding schemes are essential for representing characters from
various languages and symbols in a format that computers can understand
and process.

Types of Text Encoding Schemes

 ASCII
 Extended ASCII
 Unicode
 UTF-8
 UTF-16
 UTF-32

What does the acronym ASCII stand for, and how is it used in
computers and similar devices?:

Ans: ASCII stands for American Standard Code for Information Interchange. It
is a character encoding standard used to represent text in devices like
computers and similar systems. In ASCII, each letter, number, or symbol is
assigned a unique code number ranging from 0 to 127.

Q: What is the purpose of using the ASCII code?

ASCII is used to help computers understand letters, numbers, and symbols


by giving each one a number. This helps different devices talk to each other
using text.

Q: What is Extended ASCII, and how does it differ from the standard
ASCII table?

Ans: Extended ASCII is an 8-bit version of the standard ASCII table,


expanding it to 256 characters. It includes additional symbols, accented
letters, and other characters, while the original 128 characters are the most
commonly used for text representation.

Q: What is Unicode, and how does it differ from ASCII in terms of


character representation and encoding formats?

Ans: Unicode is a system for encoding all graphical characters from different
writing systems worldwide. Unlike ASCII's 128 characters, Unicode can
represent over a million. It uses formats like UTF-8, UTF-16, and UTF-32 for
efficient character storage and display. UTF stands for Unicode
Transformation Format.

Q: What is UTF-8, and how is it compatible with ASCII?

UTF-8 is a variable-length encoding scheme that can use 1 to 4 bytes to


represent a character. It is backward compatible with ASCII, meaning it can
read and use ASCII-encoded text without any issues. This allows text files
written in ASCII to work perfectly with UTF-8, supporting both old and new
text formats.

Q: How are characters like 'A' and the Urdu letter '‫ 'ب‬represented in
UTF-8?

Ans: In UTF-8, the letter 'A' (Unicode U+0041) is represented in binary as


01000001, which occupies 8 bits or 1 byte.

The Urdu letter '‫( 'ب‬Unicode U+0628) is represented in binary as 11011000


10101000, which takes 2 bytes in UTF-8.

You might also like