Human Language Conversion

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

HOW COMPUTERS UNDERSTAND THE HUMAN LANGUAGE CONVERSION

Learning Objectives:
By the end of this chapter, the students will be able to;
• Know the concepts of computer language.
• Understand the number system representation.

COMPUTER LANGUAGE CONVERSION

Do you know that your computer has only two digits or answers to your questions? These are 0 and
1 or yes and no.

YES is equal to 1 or “ON”


NO is equal to 0 or “OFF”

A digital system can understand positional number system only where there are a few
symbols called digits and these symbols represent different values depending on the
position they occupy in the number.
A value of each digit in a number can be determined using
• The digit
• The position of the digit in the number
• The base of the number system (where base is defined as the total number of digits
available in the number system).
As a computer programmer or an IT professional, you should understand the
following number systems which are frequently used in computers.

The number system includes decimal numbers, binary numbers, octal and hexadecimal
numbers.
S.N. Number System & Description

1 Binary Number System

Base 2. Digits used: 0, 1

2 Octal Number System


Base 8. Digits used: 0 to 7

3 Hexa Decimal Number System


Base 16. Digits used: 0 to 9, Letters used: A- F

1
1. Binary Numbers – are 1 and 0 with a base of 2. The 0 and 1 are called bit, short for binary
digit. If we have 8 bits, we call it a byte. Byte is the basic word of the computer language.
Each character on the keyboard has a decimal number and this decimal number is changed
to a binary code.
Bit - 0 1
Byte - 0 0101100

Binary Number System

Characteristics
• Uses two digits, 0 and 1.
• Also called base 2 number system
• Each position in a binary number represents a 0 power of the base (2). Example: 2 0
• Last position in a binary number represents an x power of the base (2). Example: 2 x where
x represents the last position - 1.

Example: 100112 or 10011 base 2


01102 or 0110 base 2
2. Decimal Numbers – are 0 to 9 with the base of 10
Example: 45 base 10 or 4510
4 based 10 or 410

Binary Counting
Decimal Number Binary Number
8 4 2 1
Numbers
Code
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
10 1 0 1 0

This table shows the corresponding equivalent of the decimal number 1 to 10 into a binary
digit and we use the 8, 4, 2, 1 code. With the code, we will be able to determine the equivalent
numbers of decimal numbers to binary digits.

Just remember that the code is always doubled when your number increases.
How?
1 becomes 2,
2 becomes 4,
4 becomes 8, then
8 becomes 16,
then double 16 we have 32 and so on.

2
Later on, we will use this code for the short cut method of converting a decimal number to a
binary number. Let’s proceed first to the next number system.

3. Octal

Octal Number System

Characteristics
• Uses eight digits, 0,1,2,3,4,5,6,7.
• Also called base 8 number system
• Each position in an octal number represents a 0 power of the base (8). Example: 8 0
• Last position in an octal number represents an x power of the base (8). Example: 8 x where
x represents the last position - 1.

4. Hexadecimal Number – are numbers from 0 to 9 and the letters A to F with a base of 16

Hexadecimal Number System

Characteristics
• Uses 10 digits and 6 letters, 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.
• Letters represents numbers starting from 10. A = 10, B = 11, C = 12, D = 13, E = 14, F =
15.
• Also called base 16 number system.
• Each position in a hexadecimal number represents a 0 power of the base (16). Example
160.
• Last position in a hexadecimal number represents an x power of the base (16). Example
16x where x represents the last position - 1.
A is equivalent to 10
B is equivalent to 11
C is equivalent to 12
D is equivalent to 13
E is equivalent to 14
F is equivalent to 15

Example:
2316 or 23 base 16
67816 or 678 base 16
6AB716 or 6AB7 base 16
FEBD16 or FEBD base 16

3
Hexadecimal Numbers
Binary Numbers
Decimal Number Hexadecimal Numbers
(Coded)
0 0 0 0 0 0
1 1 0 0 0 1
2 2 0 0 1 0
3 3 0 0 1 1
4 4 0 1 0 0
5 5 0 1 0 1
6 6 0 1 1 0
7 7 0 1 1 1
8 8 1 0 0 0
9 9 1 0 0 1
10 A 1 0 1 0
11 B 1 0 1 1
12 C 1 1 0 0
13 D 1 1 0 1
14 E 1 1 1 0
15 F 1 1 1 1
The table shows the equivalent of decimal numbers to hexadecimal numbers and their
corresponding binary digits.

Decimal to Other Base System


• Step 1 − Divide the decimal number to be converted by the value of the new base.
• Step 2 − Get the remainder from Step 1 as the rightmost digit (least significant digit) of
new base number.
• Step 3 − Divide the quotient of the previous divide by the new base.
• Step 4 − Record the remainder from Step 3 as the next digit (to the left) of the new base
number.
Repeat Steps 3 and 4, getting remainders from right to left, until the quotient becomes
zero in Step 3.
The last remainder thus obtained will be the Most Significant Digit (MSD) of the new
base number.
As mentioned in Steps 2 and 4, the remainders have to be arranged in the reverse order
so that the first remainder becomes the Least Significant Digit (LSD) and the last
remainder becomes the Most Significant Digit (MSD).

4
Other Base System to Decimal System

Steps
• Step 1 − Determine the column (positional) value of each digit (this depends on the
position of the digit and the base of the number system).
• Step 2 − Multiply the obtained column values (in Step 1) by the digits in the corresponding
columns.
• Step 3 − Sum the products calculated in Step 2. The total is the equivalent value in
decimal.

Conversion Exercises:

Binary to decimal:

10002 = ________________10
0 x 20 = 0
0 x 21 = 0 That’s the same answer we have in our table
0 x 22 = 0
1 x 23 = 8
810

111012 = _____________10
1 x 20 = 1
0 x 21 = 0
1 x 22 = 4
1 x 23 = 8
1 x 24 = 16
2910

10000012 = _____________10
1 x 20 = 1
0 x 21 = 0 Remember that any number multiplied to zero is
0 x 22 = 0 always zero.
0 x 23 = 0
0 x 24 = 0
0 x 25 = 0
1 x 26 = 64
6510

5
10101012 = _____________10
1 x 20 = 1
0 x 21 = 0
1 x 22 = 4
0 x 23 = 0
1 x 24 = 16
0 x 25 = 0
1 x 26 = 64
8510

Decimal to Binary Conversion

In a decimal to binary conversion, you should continuously divide the number to 2 until you reach a
number that is not divisible by 2.

• 810 = _______2
Step Operation Result Remainder

Step 1 8/2 4 0

Step 2 4/2 2 0

Step 3 2/2 1 0

Step 4 1/2 0 1
The answer of 810 10002

• 2910 = _______________2
Step Operation Result Remainder

Step 1 29 / 2 14 1

Step 2 14 / 2 7 0

Step 3 7/2 3 1

Step 4 3/2 1 1

Step 5 1/2 0 1

6
• 6510 = _______2
Step Operation Result Remainder

Step 1 65 / 2 32 1

Step 2 32 / 2 16 0

Step 3 16 / 2 8 0

Step 4 8/2 4 0

Step 5 4/2 2 0

Step 6 2/2 1 0

Step 7 1/2 0 1
The answer of 6510 10000012

• 8510 = _______2

Step Operation Result Remainder

Step 1 85 / 2 42 1

Step 2 42 / 2 21 0

Step 3 21 / 2 10 1

Step 4 10 / 2 5 0

Step 5 5/2 2 1

Step 6 2/2 1 0

Step 7 1/2 0 1
The answer of 6510 10101012

7
Shortcut method - Binary to Octal

Steps
• Step 1 − Divide the binary digits into groups of three (starting from the right).
• Step 2 − Convert each group of three binary digits to one octal digit.
Group of 3 since 8 (Octal) is 23 in Binary equivalent

Example
Binary Number − 101012
Calculating Octal Equivalent −

Step Binary Number Octal Number

Step 1 101012 010 101

Step 2 101012 28 58

Step 3 101012 258

Binary Number − 101012 = Octal Number − 258

Shortcut method - Octal to Binary

Steps
• Step 1 − Convert each octal digit to a 3 digit binary number (the octal digits may be treated
as decimal for this conversion).
• Step 2 − Combine all the resulting binary groups (of 3 digits each) into a single binary
number.
Example
Octal Number − 258
Calculating Binary Equivalent −

Step Octal Number Binary Number

Step 1 258 210 510

Step 2 258 0102 1012

Step 3 258 0101012

Octal Number − 258 = Binary Number − 101012

8
Shortcut method - Binary to Hexadecimal

Steps
• Step 1 − Divide the binary digits into groups of four (starting from the right).
• Step 2 − Convert each group of four binary digits to one hexadecimal symbol.
Group of 4 since 16 (Hexa) is 24 in Binary equivalent

Example
Binary Number − 101012
Calculating hexadecimal Equivalent −

Step Binary Number Hexadecimal Number

Step 1 101012 0001 0101

Step 2 101012 110 510

Step 3 101012 1516

Binary Number − 101012 = Hexadecimal Number − 1516

Shortcut method - Hexadecimal to Binary

Steps
• Step 1 − Convert each hexadecimal digit to a 4 digit binary number (the hexadecimal digits
may be treated as decimal for this conversion).
• Step 2 − Combine all the resulting binary groups (of 4 digits each) into a single binary
number.
Example
Hexadecimal Number − 1516
Calculating Binary Equivalent −

Step Hexadecimal Number Binary Number

Step 1 1516 110 510

Step 2 1516 00012 01012

Step 3 1516 000101012

Hexadecimal Number − 1516 = Binary Number − 101012

9
Other Base System to Non-Decimal System

Steps
• Step 1 − Convert the original number to a decimal number (base 10).
• Step 2 − Convert the decimal number so obtained to the new base number.
Example
Octal Number − 258
Calculating Binary Equivalent −
Step 1 − Convert to Decimal
Step Octal Number Decimal Number

Step 1 258 ((2 × 81) + (5 × 80))10

Step 2 258 (16 + 5 )10

Step 3 258 2110

Octal Number − 258 = Decimal Number − 2110


Step 2 − Convert Decimal to Binary
Step Operation Result Remainder

Step 1 21 / 2 10 1

Step 2 10 / 2 5 0

Step 3 5/2 2 1

Step 4 2/2 1 0

Step 5 1/2 0 1

Decimal Number − 2110 = Binary Number − 101012


Octal Number − 258 = Binary Number − 101012
Octal to Decimal Conversion
Octal Number − 125708
Calculating Decimal Equivalent −

Step Octal Number Decimal Number

Step 1 125708 ((1 × 84) + (2 × 83) + (5 × 82) + (7 × 81) + (0 × 80))10

Step 2 125708 (4096 + 1024 + 320 + 56 + 0)10

Step 3 125708 549610

Note: 125708 is normally written as 12570.

10
Hexadecimal to Decimal Conversion
Hexadecimal Number: 19FDE16
Calculating Decimal Equivalent −

Step Hexadecimal Number Decimal Number

Step 1 19FDE16 ((1 × 164) + (9 × 163) + (F × 162) + (D × 161) + (E × 160))10

Step 2 19FDE16 ((1 × 164) + (9 × 163) + (15 × 162) + (13 × 161) + (14 ×
160))10

Step 3 19FDE16 (65536 + 36864 + 3840 + 208 + 14)10

Step 4 19FDE16 10646210

Note − 19FDE16 is normally written as 19FDE.

For further reference, you can use the following links:

Number system
https://www.youtube.com/watch?v=L2zsmYaI5ww
https://www.tutorialspoint.com/computer_logical_organization/digital_number_system.htm

Tutorial Video:
Binary to Decimal
https://www.youtube.com/watch?v=VLflTjd3lWA
https://www.youtube.com/watch?v=tfKe8PPI2zs

Decimal to Binary
https://www.youtube.com/watch?v=OezK_zTyvAQ
https://www.youtube.com/watch?v=rsxT4FfRBaM
https://www.youtube.com/watch?v=rsxT4FfRBaM&t=66s

Binary to Hexadecimal
https://www.youtube.com/watch?v=tSLKOKGQq0Y

Decimal to Hexadecimal
https://www.youtube.com/watch?v=QJW6qnfhC70

11
Task:

Convert the following: Show your solution and reflect the base.

Binary to Decimal, Octal, and Hexadecimal


1. 10001012
2. 100110012
3. 11111001112
4. 111111001012
5. 100000100012

Decimal to Binary, Octal, and Hexadecimal


6. 6910
7. 15310
8. 99910
9. 202110
10. 104110

Octal to Binary, Decimal, and Hexadecimal


11. 1058
12. 2318
13. 17478
14. 37458
15. 20218

Hexadecimal to Binary, Decimal, and Octal


16. 4516
17. 9916
18. 3E716
19. 7E516
20. 41116

12

You might also like