[go: up one dir, main page]

0% found this document useful (0 votes)
40 views12 pages

Number Systems and Data Representation

ISC CLASS XI NUMBER SYSREM AND CONVERSION NOTES
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views12 pages

Number Systems and Data Representation

ISC CLASS XI NUMBER SYSREM AND CONVERSION NOTES
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

© Copyright Reserved by Debanjan Gupta

NUMBER SYSTEMS AND DATA REPRESENTATION


NUMBER SYSTEMS:
Number Systems are the ways of representing numbers in different forms. Each number
System involves definite set of digits while writing a number. It is known as base of the
number.
Ex: A number with base 5 has only 5 digits (0,1,2,4)
DIFFERENT NUMBER SYSTEMS:
DECIMAL NUMBER SYSTEM:
In a decimal number system, a number is represented using 10 digits – 0,1,2,3,4,5,6,7,8 and
9
Thus, it is known as a base 10 number system.
Ex: (2457)10 or (587)10

BINARY NUMBER SYSTEM:


A number system which uses only 2 digits – 0 and 1 to represent a number is known as a
binary system.
It is known as base 2 number System. In computer, binary number is represented as a
pattern of ON and OFF of the switches or HIGH and LOW.
Ex: (011)2 or (110011)2

OCTAL NUMBER SYSTEM:


A number system which uses 8 digits – 0,1,2,3,4,5,6 and 7 is known as Octal System.
It is a base 8 number System.
Ex: (4105)8 or (6332)8

HEXADECIMAL NUMBER SYSTEM:


A number system which uses 16 digits – 0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, F, (i.e., 0-9 to
decimal and A-F of hex system) is known as Hexadecimal System.
It is a base 16 number System.
Ex: (1ABC3)16 or (BC561)16
© Copyright Reserved by Debanjan Gupta

INTER-CONVERSION OF NUMBER SYSTEMS:

DECIMAL TO OTHER SYSTEMS:


1. DECIMAL TO BINARY:
To convert a decimal number to binary, the following steps should be followed:
• Divide the decimal number by 2 and obtain Quotient and Remainder. The remainder
will be the LSB (Least Significant Bit) of the Binary Number.
• Divide the Quotient by 2 again to obtain the next quotient and remainder.
• Repeat the steps until the quotient becomes 0.
• The last remainder will be the MSB (most significant bit) of the binary number.
• Arrange all the remainders from MSB to LSB to get the equivalent binary form of
decimal number.

EX: Convert (25)10 to Binary Equivalent:

REMAINDER
2 25
2 12 1 LSB
2 6 0

2 3 0
1 1

Therefore, (25)10 = (11001)2

MSB
© Copyright Reserved by Debanjan Gupta

DECIMAL TO BINARY CONVERSION OF REAL NUMBERS:


To convert a real decimal number to binary, the integral and fractional parts are converted
separately.
(85.27) 10

Integral part Fractional part

REMAINDER
2 85 1
2 42 0
2 21 1
2 10 0
2 5 1
2 2 0
1

0.27 x 2 = 0.54 -> 0


0.54 x 2 = 1.08 -> 1
0.08 x 2 = 0.16 -> 0
0.15 x 2 = 0.32 -> 0
0.32 x 2 = 0.64 -> 0

Now, put both the values together (integral and decimal part together) to get the required
binary equivalent. The binary digits of integral part is to be arranged from bottom to top
and vice-versa for the fractional part.
Thus, (85.27)10 = (1010101. 01000)2 approx.

2. DECIMAL TO OCTAL
To, convert a decimal number to octal, follow the same procedure as in case of decimal to
binary, only instead to 2 the decimal number should be divided by 8
© Copyright Reserved by Debanjan Gupta

Ex: Convert (395)10 to Octal

8 395 3
8 49 1
6

(395)10 = (613)8

CONVERSION OF DECIMAL TO OCTAL OF REAL NUMBERS


To convert a real decimal number to octal, the integral and fractional parts are converted
separately.
(445.37) 10

Integral Part Fractional Part


8 445 5

8 55 7 0.37 x 8 = 2.96 -> 2


0.96 x 8 = 7.68 -> 7
0. 68 x 8 = 5.44 ->5
6 0. 44 x 8 = 3.52 -> 3

Therefore, (445.37)10 = (675.2753)8 approx

3. DECIMAL TO HEXADECIMAL
To, convert a decimal number to hexadecimal, follow the same procedure as in case of
decimal to octal, only instead to 8 the decimal number should be divided by 16
© Copyright Reserved by Debanjan Gupta

Ex: Convert (2699)10 to Hexadecimal

16 2699 11(B)

16 168 8

10(A)

Therefore, (2699)10 = (A8B)16

BINARY TO OTHER SYSTEMS:


1. BINARY TO DECIMAL
To convert a decimal number to binary, the following steps should be followed:
• Multiply each digit of binary number with 20, 21, 23 …. respectively, from right to left.
• Add all the products to get the equivalent decimal number.

EX: Convert (110101)2 to Decimal

1 1 0 1 0 1 Binary
Number
25 24 23 22 21 20 Power
32 16 8 4 2 1 Value

Hence, the required decimal number is:


(1x32) + (1x16) + (0 x 8) + (1 x 4) + (0 x 2) + (1 x 1)
32 + 15 + 0 + 4 + 0 + 1
(53)10

CONVERSION OF BINARY FRACTIONAL NUMBERS TO DECIMAL


To convert a fractional binary number to decimal, the integral and fractional parts are
converted separately.
(10101.101)2

Integral part Fractional part


© Copyright Reserved by Debanjan Gupta

1 0 1 0 1 . 1 0 1 Binary
Number
24 23 22 21 20 . 2-1 2-2 2-3 Power
16 8 4 2 1 . 0.5 0.25 0.125 Value

(1x16) + (0x8) +(1x4) +(0x2) + (1x1) . (1x0.5) +(0x0.25) +(1x0.125)


16 + 0 + 4 + 0 +1 . 0.5 + 0 + 0.125
(21. 625) 10

2. BINARY TO OCTAL:

Octal Digits Binary Equivalent


0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111

Binary to Octal Conversion can also be done using the above table:
Ex: Convert (1100101)2 to Octal

001 100 101 Binary Number


1 4 5 Octal Equivalent

Therefore, (1100101)2 = (145)8


3. BINARY TO HEXADECIMAL:
In order to Convert a Binary number to Hexadecimal the following table can be used:

HEXADECIMAL BINARY
DIGITS EQUIVALENT
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
© Copyright Reserved by Debanjan Gupta

6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111

Ex : Convert (11000110111)2 to Hexadecimal


0110 0011 0111 Binary Number
6 3 7 Hexadecimal
Equivalent

Therefore, (11000110111)2 = (637)16

OCTAL TO OTHER SYSTEMS:


1. OCTAL TO DECIMAL
Follow the same method in case of binary to decimal. Instead of 2 , 8 should be used
Ex: Convert (4105)8 to Decimal

4 1 0 5 Octal Number
83 82 81 80 Power
512 64 6 1 Value

(4x512) + (1x64) + (0x8) + (5x1)


2048 + 64 + 0 + 5 = (2117)10

CONVERSION OF OCTAL TO DECIMAL OF REAL NUMBERS


To convert a fractional octal number to decimal, the integral and fractional parts are
converted separately.
(5412.35)8

Integral part Fractional part


© Copyright Reserved by Debanjan Gupta

5 4 1 2 . 3 5 Octal
Number
83 82 81 80 . 8-1 8 -2 Power
512 64 8 1 . 0.125 0.015625 Value

(5x512) + (4x64) + (8x1) + (2x1) . (3x0.125) + (5x0.015625)


2560 + 256 + 8 + 2 . 0.375 + 0.078125
(2826.453125)10

2. CONVERSION OF OCTAL TO BINARY:


An octal number uses 8 digits (0 to 7), this can be directly converted to binary using
3-bits form as shown in the table:
Octal Digits Binary Equivalent
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
Ex: Convert (312)8 to Binary

3 = 011
1 = 001
2 = 010 Therefore, (312)8 = (011001010)2

Ex: Convert (4357.241)8 to Binary

4 = 100 2 = 010
3 = 011 4 = 100
5 = 101 1 = 001
7 = 111 Therefore, (4357.241)8 = (100011101111. 010100001)2

3. OCTAL TO HEXADECIMAL
Ex: Convert (342.41)8 to Hexadecimal:
3 4 2 . 4 1

011 100 010 . 100 001

Binary Equivalent: (011100010.100001)2


Now, group them in 4-bits
© Copyright Reserved by Debanjan Gupta

0000 = 0
1110 = E
0010 = 2
.
1000 = 8
0100 = 4

Therefore, (342.41)8 = (0E2.84)16

HEXADECIMAL TO OTHER SYSTEMS:


1. HEXADECIMAL TO DECIMAL:
Follow the same method in case of binary to decimal. Instead of 2 , 16 should be
used

Ex: Convert (7CE)16 to Decimal

7 C(12) E(14) Hexadecimal


Number
162 161 160 Power
256 16 1 Value

(7x256) + (12x16) + (14x1)


1792 + 192 + 14
(1998)10

CONVERSION OF HEXADECIMAL TO DECIMAL OF REAL NUMBERS


To convert a fractional hexadecimal number to decimal, the integral and fractional parts are
converted separately.
(A4B.C2)16

Integral part Fractional part

A(10) 4 B(11) . C(12) 2 HexadecimalNumber


162 161 160 . 16-1 16 -2 Power
256 16 1 . 0.0625 0.0039062 Value

(10x256) + (4x16) + (11x1) . (12x0.0625) + (2x0.0039062)


2560 + 64 + 11 . 0.75 + 0.0078124
(2635.7578)10
© Copyright Reserved by Debanjan Gupta

2. HEXADECIMAL TO BINARY

In order to Convert a Hexadecimal to Binary the following table can be used:

HEXADECIMAL BINARY
DIGITS EQUIVALENT
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111

Ex: Convert (D97)16 to Binary

D 9 7 Hexadecimal
Number
13 9 7 Hexadecimal Value
1101 1001 0111 Binary Equivalent

Therefore, (D97)16 = (110110010111)2


© Copyright Reserved by Debanjan Gupta

CODING:
Write a menu driven to:
1. Convert decimal to binary
2. Convert binary to decimal
Based on user’s choice.
# USING JAVA:

import java.util.*;
class NumberConversion{
void decToBinary(int decimal) {
int[] binary = new int[1000];
int i = 0,copy=decimal;
while (decimal > 0) {
binary[i] = decimal % 2;
decimal /= 2;
i++;
}
System.out.println("The Binary equivalent of "+copy+" is:");
for(int j=0;j<i;j++){
System.out.print (binary[j]);
}
System.out.println();
}

void binaryTodec(int binary) {


int decimalNumber = 0, i = 0,copy=binary;
long remainder;

while (binary != 0) {
remainder = binary % 10;
binary /= 10;
decimalNumber += remainder * Math.pow(2, i);
++i;
}
System.out.println("The Decimal Equivalent of "+copy+" is
"+decimalNumber);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {

System.out.println("Enter a choice ");


System.out.println("Enter 1. to Convert Decimal to Binary");
System.out.println("Enter 2. to convert Binary to Decimal");
int choice = sc.nextInt();
NumberConversion obj = new NumberConversion();

switch (choice) {
case 1:
System.out.println("Enter a Decimal NUmber");
int dec = sc.nextInt();
obj.decToBinary(dec);
break;

case 2:
System.out.println("Enter a Binary Number");
int bin = sc.nextInt();
© Copyright Reserved by Debanjan Gupta

obj.binaryTodec(bin);
break;

default:
System.out.println("INVALID CHOICE");
}
}

}
}

#USING PYTHON
#PYTHON

def decimal_to_binary(decimal_number):
return bin(decimal_number)[2:]

def binary_to_decimal(binary_number):
return int(binary_number, 2)

while True:
print("Choose an option:")
print("1. Convert decimal to binary")
print("2. Convert binary to decimal")
print("3. Exit")
choice = int(input())

if choice == 1:
decimal_number = int(input("Enter a decimal number: "))
binary_number = decimal_to_binary(decimal_number)
print(binary_number)

elif choice == 2:
binary_number = input("Enter a binary number: ")
decimal_number = binary_to_decimal(binary_number)
print(decimal_number)

elif choice == 3:
print("Exiting program...")
break

else:
print("Invalid option")

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

You might also like