CS2
CS2
Number System:
It is a systematic way to represent numbers in different ways. Each number system has its own
Base, that is a number and that number of symbols or digits used.
1. Most Significant Digit (MSD): The digit with most weight is called MSD. MSD is also called
Left Most Digit(LMD)
2. Least Significant Digit (LSD): The digit with least weight is called LSD. LSD is also called
Right Most Digit(RMD)
eg: 106 : Here MSD : 1 and LSD : 6
345.78: Here MSD : 3 and LSD : 8
3. A Binary Digit is also called a bit.
4. The weight of each digit of a number can be represented by the power of its base.
Number conversions:
In general, to convert a decimal number into another number system(binary or octal or
hexadecimal) do the following. Divide the number successively by the base of the number
system do you want to convert and write down the remainders from bottom to top.
To convert a decimal fraction into another number system .multiply the number by the base of
the number system do you want to convert then integer part and fractional part are separated
again multiply the fractional part by the base and do the steps repeatedly until the fractional part
becomes zero. Finally write down the integer part from top to bottom.
Decimal to Binary:
Divide the number by the base 2 successively and write down the remainders from bottom to
top.
(0.140625)10 = (0.11)8
Decimal to Hexadecimal:
Divide the number by the base 16 successively and write down the remainders from bottom to
top.
Converting a number from any number system into decimal: For this multiply each digit by its
corresponding weight and sum it up.
Binary to decimal conversion:
For this multiply each bit by its corresponding weight and sum it up. The weights are power of 2.
1 × 83 + 0 × 82 + 0 × 81 + 7 × 80
= 512 + 0 + 0 + 7
=(519)10
Converting octal fraction to decimal (600.005)8 =()10?
(10100110)2= (246)8
Binary to Hexadecimal conversion:
Divide the binary number into groups of 4 bits starting from the right to left(But in the fractional
part start dividing from left to right). Insert necessary zeros in the left side(or right side in the
case of fractional part)if needed and write down the corresponding Hexadecimal equivalent.
eg: (100100110)2 = ()16?
Insert 3 zeros in the left side to form 4 bits group
(100100110)2 = (126)16
Octal to Hexadecimal conversion:
First convert octal number into binary(see 1.6.7), then convert this binary into hexadecimal(also
see 1.6.10)
eg: Convert (67)8 = ( )16
Step I: First convert this number into binary equivalent for this do the following:
Step II: Next convert this number into hexadecimal equivalent for this do the following.
Step II. Next convert this number into octal equivalent. For this do the following.
So the answer is (A1)16 = (241)8
Data representation:
The data stored in the computer memory is in the form of binary.
Representation of integers
There are three ways to represent integers in computer. They are as follows:
1. Sign and Magnitude Representation (SMR)
2. 1’s Complement Representation
3. 2’s Complement Representation
1. SMR:
Normally a number has two parts sign and magnitude, eg: Consider a number+5. Here + is the
sign and 5 is the magnitude. In SMR the most significant Bit (MSB) is used to represent the
sign. If MSB is 0 sign is +ve and MSB is 1 sign is -ve. eg: If a computer has word size is 1 byte
then
Here MSB is used for sign then the remaining 7 bits are used to represent magnitude. So we
can , represent 27 = 128 numbers. But there are negative and positive numbers. So 128 + 128
= 256 number. The numbers are 0 to +127 and 0 to -127. Here zero is repeated. So we can
represent 256 – 1 = 255 numbers.
2. 1’s Complement Representation:
To get the 1’s complement of a binary number, just replace every 0 with 1 and every 1 with 0.
Negative numbers are represented using 1’s complement but +ve number has no 1 ’s
complement,
eg:
(i) To find the 1’s complement of -21
+21 = 00010101
To get the 1’s complement change all 0 to 1 and.all 1 to 0.
-21 = 11101010
1’s complement of-21 is 11101010
(ii) Find the 1’s complement of +21. Positive numbers are represented by using SMR.
+21 = 00010101 (No need to take the 1’s complement)
3. 2’s Complement Representation:
To get the 2’s complement of a binary number, just add 1 to its 1’s complement +ve number
has no 2’s complement.
eg: To find the 2’s complement of -21
+21 = 00010101
First take the 1’s complement for this change all 1 to 0 and all 0 to 1
Binary subtraction:
The rules for subtracting a binary digit from another digit.
Step 4: Ignore the carry the result is positive. Hence the result is 101111.
Introduction to Boolean algebra:
The name Boolean Algebra is given to honour the British mathematician George Boole.
Boolean algebra deals with two states true or false otherwise Yes or No and numerically either
0 or 1.
Binary valued quantities:
A logical decision which gives YES or No values is a binary decision, A statement which gives
YES or NO values(TRUE or FALSE) is a logical statement or truth function. A variable which
can assign TRUE or FALSE (1 or 0) values is a logical variable
Boolean operators and logic gates:
Logical Operators are AND, OR and NOT. A logical gate is a physical device (electronic
circuit)that can perform logical operations on one or more logical inputs and produce a single
logical output. A table represents the set f all possible values and the corresponding results in a
statement is called truth table.
1. The OR operator and OR gate:
The OR operator gives a 1 either one of the operands is 1. If both operands are 0, it produces
0. The truth table of X OR Y is
The logical OR gate is given below.
The truth table and the gate for the Boolean expression Y = A + B + C
The truth table and the gate for the Boolean expression Y = A . B . C
3. The NOT operator and NOT gate:
It produces the vice versa. NOT gate is also called inverter. It is a unary operator that means it
has only one input and one output. The truth table of NOT X is
Principle of Duality:
When changing the OR(+) to AND(.), AND (.) to OR(+), 0 to 1 and 1 to 0 in a Boolean
expression we will get another Boolean relation which is the dual of the first, this is the principle
of duality.
Basic theorems of Boolean algebra:
There are some standard and accepted rules in every theory, these rules are known as axioms
of the theory.
Identity law:
If X is a Boolean variable, the law states that
1. 0 + X = X
2. 1 + X = 1 (these are additive identity law)
3. 0 . X = 0
4. 1 . X = X (these are multiplicative identity law)
Following are the truth tables
Idempotent law:
This law states that
1. X + X = X
2. X . X = X
Involution law:
This states that
X¯¯¯¯¯¯¯¯=x
The compliment of compliment of a number is the number itself.
Complimentary law:
This law states that
1. x+x¯=1
2. x⋅x¯=0
The truth table is given below
Commutative law:
This law allows to change the position of variable in OR and AND
1. X + Y = Y + X
2. X . Y = Y . X
The truth table is given below
Associative law:
It allows grouping of variables differently
1. X + (Y + Z) = (X + Y) + Z
2. X . (Y . Z) = (X . Y) . Z
The truth table is given below
Distributive law:
This law allows expansion of multiplication over addition and also allows addition operation over
multiplication.
1. X . (Y + Z) = X . Y + X . Z
2. X + Y . Z = (X + Y) . (X + Z)
The truth table is given below
Absorption law:
It is a kind of distributive law in which two variables are used and result will be one of them
1. X + (X . Y) = X
2. X . (X + Y) = X
The truth table is given below
De Morgan’s theorem:
Demorgan’s first theorem states that
X+Y¯¯¯¯¯¯¯¯¯¯¯¯¯=X¯¯¯¯⋅Y¯¯¯¯
ie. the compliment of sum of two variables equals product of their compliments.
The second theorem states that
X.Y¯¯¯¯¯¯¯¯¯¯=X¯¯¯¯+Y¯¯¯¯
ie. The compliment of the product of two variables equals the sum of the compliment of those
variables.
Circuit designing for simple Boolean expressions:
By using basic gates such as AND, OR and NOT gates we can create logic circuits.
Universal gates:
By using NAND and NOR gates only we can create other gates hence these gates are called
Universal gate.
NAND gate:
The output of AND gate is inverted by NOT gate is the NAND gate
NOR gate:
The output of OR gate is inverted by NOT gate is the NOR gate.
Number System
1. When we convert 10010 binary numbers to decimals. Then the solution is :
2010
1810
1410
1610
Answer
1810
2. How many bits are in 1 byte?
1024
10
8
16
Answer
8
3. An organized way of representing numbers is called?
Character System
Number system
Integer System
None of these
Answer
Number system
4. How many different characters can ASCLL represent?
90
1024
128
54
Answer
128
5. How real numbers are stored by the computer?
Floating Point Representation using Mantissa and Exponent
ASCLL
Binary
Floating Boat Representation
Answer
Floating Point Representation using Mantissa and Exponent
6. How text is represented by the computer?
Unicode
Bitmap
ASCLL
Floating-point Representation
Answer
ASCLL
7. How many unique symbols in the Hexadecimal number system?
16
12
10
8
Answer
16
8. Octal equivalent of hexadecimal code F3A1 is :
158661
171641
176541
173101
Answer
176541
9. Using ASCLL, how many bits are required for 1 character?
11
8
9
14
Answer
8
10. The binary equivalent of the decimal number 0.4375 is :
0.1010
0.1100
0.1011
0.0111
Answer
0.0111
11. How graphics are represented by the computer?
Unicode
ASCLL
Bitmap
Binary
Answer
Bitmap
12. How many processes for converting ( integer ) from decimal to binary?
Four
There
Two
One
Answer
Two
13. Octal number system is :
8
10
4
2
Answer
4
14. How many unique symbols in a decimal number system?
8
10
4
2
Answer
10
15. What digits are used to store numbers, letters, etc.
0-1
3-4
0-5
1-9
Answer
0-1
16. How many bytes are in 1 kilobyte?
90
145
8
1024
Answer
1024