110 likes | 157 Views
Lecture 02: OCTAL AND HEXADECIMAL NUMBER SYSTEMS. PROF. INDRANIL SENGUPTA DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING. Octal Number System. A compact way to represent binary numbers. Group of three binary digits are represented by a octal digit. Octal digits are 0 to 7.
E N D
Lecture 02: OCTAL AND HEXADECIMAL NUMBER SYSTEMS PROF. INDRANIL SENGUPTA DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Octal Number System • A compact way to represent binary numbers. • Group of three binary digits are represented by a octal digit. • Octal digits are 0 to 7.
Binary to Octal Conversion • For the integer part: • Scan the binary number from right to left. • Translate each group of three bits into the corresponding octal digit. • Add leading zeros if necessary. • For the fractional part: • Scan the binary number from left to right. • Translate each group of three bits into the corresponding octal digit. • Add trailing zeros if necessary.
Examples (Binary to Octal) • (101101000011)2 = (5503)8 • (1010100001)2 = (1241)8 • (.1000011)2 = (.414)8 • (11. 0101111)2 = (3.274)8 Two leading 0s are added Two trailing 0s are added A leading 0 and two trailing 0s are added
Octal to Binary Conversion • Translate every octal digit into its 3-bit binary equivalent. • Examples: (1645)8= (001 110 100 101)2 (22.172)8= (010 010 . 001 111 010)2 (1.54)8= (001 . 101 100)2
Hexadecimal Number System • A compact way to represent binary numbers. • Group of four binary digits are represented by a hexadecimal digit. • Hexadecimal digits are 0 to 9, A to F.
Binary to Hexadecimal Conversion • For the integer part: • Scan the binary number from right to left. • Translate each group of four bits into the corresponding hexadecimal digit. • Add leading zeros if necessary. • For the fractional part: • Scan the binary number from left to right. • Translate each group of four bits into the corresponding hexadecimal digit. • Add trailing zeros if necessary.
Examples (Binary to Hexadecimal) • (101101000011)2 = (B43)16 • (1010100001)2 = (2A1)16 • (.1000010)2 = (.84)16 • (101 . 0101111)2 = (5.5E)16 Two leading 0s are added A trailing 0 is added A leading 0 and trailing 0 are added
Hexadecimal to Binary Conversion • Translate every hexadecimal digit into its 4-bit binary equivalent. • Examples: (3A5)16 = (0011 1010 0101)2 (12.3D)16 = (0001 0010 . 0011 1101)2 (1.8)16 = (0001 . 1000)2
Decimal to Radix-r and Vice Versa • We follow a principle similar to decimal-binary and binary-decimal conversion as discussed earlier. • Radix-r to decimal: • Multiply each digit by corresponding weight and add them up. • Decimal to radix-r: • For the integer part, repeatedly divide the number by r and accumulate the remainder. Remainders are arranged in reverse order. • For the fractional part, repeatedly multiply by r, and accumulate & discard the integer part. The digits are arranged in the order they are generated.