Docsity

Binary and Hexadecimal Number Conversion, Study notes of Data Structures and Algorithms

Toggle sidebar
bg1
CONVERTING BINARY TO DECIMAL
www.permadi.com/tutorial/numBinToDec/
Binary has two numerical notations: 0 and 1.
That is why we also call binary numbers with base 2 numeric system.
Decimal has 10 variants of numerical notations: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
That is why we call it base 10 numeric system.
2^7
2^6
2^5
2^4
2^3
2^2
2^1
128
64
32
16
8
4
2
Example #1
Convert BINARY 11101 to DECIMAL
=1*(2^4) + 1*(2^3) + 1*(2^2) + 0*(2^1) + 1*(2^0)
1*(16) + 1*(8) + 1*(4) + 0*(2) + 1*(1)
= 16+8+4+0+1
= 29
Example #2
Convert BINARY 1010 to DECIMAL
MULTIPLICATION
RESULT
0*(2^0)
0
1*(2^1)
2
0*(2^2)
0
1*(2^3)
8
ANSWER
10
CONVERTING DECIMAL TO BINARY
www.learning-about-computers.com/tutorials/binary_and_hexidecimal.shtml
Example
Let's convert 835 to binary.
The most significant bit is the left number in the answer and the least significant bit is on the right
end giving us an answer of: 11010000112
pf3
pf4
pf5

Partial preview of the text

Download Binary and Hexadecimal Number Conversion and more Study notes Data Structures and Algorithms in PDF only on Docsity!

CONVERTING BINARY TO DECIMAL

www.permadi.com/tutorial/numBinToDec/

Binary has two numerical notations: 0 and 1. That is why we also call binary numbers with base 2 numeric system.

Decimal has 10 variants of numerical notations: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. That is why we call it base 10 numeric system.

2^ 7 2^ 6 2^ 5 2^ 4 2^ 3 2^ 2 2^ 1 2^ 0

Example # Convert BINARY 11101 to DECIMAL

=1(2^4) + 1(2^3) + 1(2^2) + 0(2^1) + 1(2^0) 1(16) + 1(8) + 1(4) + 0(2) + 1(1) = 16+8+4+0+ = 29

Example # Convert BINARY 1010 to DECIMAL MULTIPLICATION RESULT 0(2^0) 0 1(2^1) 2 0(2^2) 0 1(2^3) 8 ANSWER 10

CONVERTING DECIMAL TO BINARY

www.learning-about-computers.com/tutorials/binary_and_hexidecimal.shtml

Example Let's convert 835 to binary.

The most significant bit is the left number in the answer and the least significant bit is on the right end giving us an answer of: 1101000011 2

CONVERTING DECIMAL TO HEXADECIMAL

www.permadi.com/tutorial/numDecToHec/

Hexadecimal has 16 variants of numerical notations: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. That is why we call it base 16 numeric system.

Decimal has 10 variants of numerical notations: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. That is why we call it base 10 numeric system.

HEXADECIMAL 0 1 2 3 4 5 6 7 8 9 A B C D E F

DECIMAL 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Example # 1 Convert the number 256 DECIMAL to HEXADECIMAL

DIVISION RESULT REMAINDER (in HEX) 256 / 16 16 0 16 / 16 1 0 1 / 16 0 1 ANSWER 100

Example # 2 Convert the number 921 DECIMAL to HEXADECIMAL

DIVISION RESULT REMAINDER (in HEX)

921 / 16 57 9

57 / 16 3 9

3 / 16 0 3

ANSWER 399

Example # 3 Convert the number 188 DECIMAL to HEXADECIMAL

DIVISION RESULT

REMAINDER

(in HEX)

188 / 16 11 C (12 decimal)

11 / 16 0 B (11 decimal)

ANSWER BC

Note: Here, the answer would not be 1112, but BC. Remember to write down the remainder in hex, not decimal.

CONVERTING BINARY TO HEXADECIMAL

http://www.rapidtables.com/convert/number/how-binary-to-hex.htm

HEXADECIMAL 0 1 2 3 4 5 6 7 8 9 A B C D E F

DECIMAL 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

One bit of Hexadecimal represents 4 bits Binary number.

This also means:

Four bits of Binary number is represented in One bit Hexadecimal.

Convert each 4 binary digits to hexadecimal digit according to this table:

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

Example 1 Convert (01001110) 2 to hex: (0100) 2 = (4) 16 (1110) 2 = (E) 16 So (01001110) 2 = (4E) 16

Example 2 Convert (0100101000000001) 2 to hex: (0100) 2 = (4) 16 (1010) 2 = (A) 16 (0000) 2 = (0) 16 (0001) 2 = (1) 16 So (0100101000000001) 2 = (4A01) 16

CONVERTING HEXADECIMAL TO BINARY

One bit of Hexadecimal represents 4 bits Binary number.

This also means:

Four bits of Binary number is represented in One bit Hexadecimal.

Convert each hexadecimal digit to 4 binary digits according to this table:

Hexadecimal Binary 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

Example 1

Convert (4E) 16 to binary: (4) 16 = (0100) 2 (E) 16 = (1110) 2 So (4E) 16 = (01001110) 2

Example 2

Convert (4A01) 16 to binary: (4) 16 = (0100) 2 (A) 16 = (1010) 2 (0) 16 = (0000) 2 (1) 16 = (0001) 2 So (4A01) 16 = (0100101000000001) 2