Number System Conversions
Number System Conversions
Number System Conversions
Objective:
To understand the concepts of number system conversions and to practice converting numbers between
different systems such as Binary, Decimal, Octal, and Hexadecimal.
Introduction:
A number system is a writing system for expressing numbers; it's a mathematical notation for
representing numbers in a consistent manner using digits or other symbols. Different number systems
are used in various areas of computing and mathematics.
Understanding number system conversions is essential in areas like computer science, programming, and
digital electronics.
The decimal number system is base-10, using digits from 0 to 9. To convert a decimal number to binary,
repeatedly divide the number by 2 and record the remainders. The binary number is the sequence of
remainders in reverse order.
13 ÷ 2 = 6, remainder = 1
6 ÷ 2 = 3, remainder = 0
3 ÷ 2 = 1, remainder = 1
1 ÷ 2 = 0, remainder = 1
To convert a binary number to decimal, multiply each bit by 2 raised to the power of its position (starting
from 0 from the rightmost bit) and sum the results.
Decimal representation: 8 + 4 + 0 + 1 = 13
Decimal numbers can be converted to octal (base 8) using a method similar to decimal to binary
conversion, except you divide by 8 instead of 2.
35 ÷ 8 = 4, remainder = 3
4 ÷ 8 = 0, remainder = 4
Octal representation: 43
To convert an octal number to decimal, multiply each digit by 8 raised to the power of its position
(starting from 0) and sum the results.
The method is similar to decimal to binary and decimal to octal, but you divide by 16 and use
hexadecimal digits (0-9 and A-F).
15 ÷ 16 = 0, remainder = 15 (F in hex)
Hexadecimal representation: FE
To convert a hexadecimal number to decimal, multiply each digit by 16 raised to the power of its position
(starting from 0) and sum the results.
Octal to Binary: Convert each octal digit into its 3-bit binary equivalent.
Binary to Hexadecimal: Group the binary number into sets of four bits from right to left, then
convert each group into a hexadecimal digit.
Hexadecimal to Binary: Convert each hexadecimal digit into its 4-bit binary equivalent.
Lab Tasks:
2. 231
3. 1024
1. 101101
2. 11101101
3. 100010101
1. 72
2. 156
3. 205
1. 105
2. 232
3. 67
1. 123
2. 255
3. 789
1. 7F
2. 1A3
3. B2
Lab Manual: Number System Conversions
Practical Questions and Solutions:
Solution:
25 ÷ 2 = 12, remainder = 1
12 ÷ 2 = 6, remainder = 0
6 ÷ 2 = 3, remainder = 0
3 ÷ 2 = 1, remainder = 1
1 ÷ 2 = 0, remainder = 1
Solution:
Decimal representation: 32 + 0 + 8 + 0 + 2 + 0 = 42
Assignment 1:
o 1024
o 255
o 512
o 1110101
o 10101111
Lab Manual: Number System Conversions
Assignment 2:
o 3F
o A5
o 7D
o 67
o 124
Assignment 3:
o 100
o 48
o 77
Binary to octal conversion is simple if you group the binary number into sets of three bits (starting from
the right). Each group of three bits is then converted into its octal equivalent.
1. Group the binary number into groups of 3 bits, starting from the right. If necessary, pad with
leading zeros.
Group the binary digits into sets of 3 bits from right to left: 011 010 111
o 011 → 3
o 010 → 2
o 111 → 7
To convert an octal number to binary, simply convert each individual octal digit into its 3-bit binary
equivalent.
1. For each octal digit, write its binary equivalent using 3 bits.
3 → 011
2 → 010
7 → 111
To convert from binary to hexadecimal, group the binary number into sets of four bits (starting from the
right). Each group of four bits is then converted into its hexadecimal equivalent.
1. Group the binary number into sets of 4 bits, starting from the right. If necessary, pad with
leading zeros.
Group the binary digits into sets of 4 bits: 1101 0110 1011
o 1101 → D
o 0110 → 6
o 1011 → B
To convert a hexadecimal number to binary, convert each hexadecimal digit into its 4-bit binary
equivalent.
Lab Manual: Number System Conversions
Steps for Hexadecimal to Binary Conversion:
A → 1010
5 → 0101
To convert from octal to hexadecimal, the easiest way is to first convert the octal number to binary and
then from binary to hexadecimal.
o 2 → 010
o 5 → 101
o 4 → 100
0010 → 2
1011 → B
o B → 1011
o 2 → 0010
o Group the binary number into sets of 3 bits from the right: 010 110 010
010 → 2
110 → 6
010 → 2
1. 111101101
2. 1010111101
3. 110101101011
1. A1
2. 7F
3. B3D
Lab Manual: Number System Conversions
Problem 3: Decimal to Binary, Octal, and Hexadecimal
Convert the following decimal numbers into binary, octal, and hexadecimal:
1. 185
2. 348
3. 725
Task 1: Convert the following hexadecimal and binary numbers into all other systems (binary, octal,
decimal, and hexadecimal):
1. 1A3
2. 101011
3. 234
4. F4
5. 1111101010
Task 2: Create your own number in binary, octal, and hexadecimal. Then, convert it into all other
systems (binary to decimal, octal, hexadecimal, etc.).
1. Use number system conversions in a programming language such as Python to automate these
conversions. Write a program that:
o Converts octal and hexadecimal numbers to decimal, binary, and each other.
Assignment 1:
1. Convert the following numbers into all systems (binary, decimal, octal, and hexadecimal):
Lab Manual: Number System Conversions
o 92
o 56
o 1035
Assignment 2:
1. Convert the following binary, octal, and hexadecimal numbers into decimal:
o 101101
o 123 (octal)
o A1 (hexadecimal)
Assignment 3:
1. Convert the following decimal numbers into binary, octal, and hexadecimal:
o 432
o 77
o 1001
Understanding number systems and their conversions is crucial not just for theory but for real-world
applications. In computing, different number systems are used for different tasks. Below are some
examples of how number system conversions are applied in practical scenarios.
In digital electronics, numbers are often represented in binary, octal, or hexadecimal due to the nature of
digital circuits (which operate on binary logic). Hexadecimal and octal are often used for compact
representation of binary numbers.
Binary is used to represent the on/off states in digital circuits, and in computer processors for
executing operations.
Octal and Hexadecimal provide compact ways to represent long binary numbers, especially
useful for debugging machine-level code or when working with assembly language.
Example:
A processor might use binary to execute an instruction, but an engineer might write the
instruction in hexadecimal for convenience, as it’s more compact and easier to read.
In computers, memory addresses are often expressed in hexadecimal. Each address points to a specific
memory location, which could contain data in binary form.
Lab Manual: Number System Conversions
Example:
A memory address might be written as 0x2F7 (hexadecimal), which can be converted to binary
as 10111110111 and used by the processor to access the data in that memory location.
In networking, IP addresses are typically represented in decimal (IPv4 format) or hexadecimal (IPv6
format). Understanding how to convert between these formats helps network engineers and system
administrators manage addresses and configurations.
Example:
In digital graphics, colors are often represented in hexadecimal format, particularly for web design. Each
color is described by three components: red, green, and blue (RGB). Each component is typically a 2-digit
hexadecimal number.
Example:
The color white in hexadecimal is represented as #FFFFFF. This is a shorthand for 255, 255, 255 in
RGB (the maximum values for red, green, and blue).
In computing, negative numbers are often represented using two’s complement notation in binary. This
system allows for efficient arithmetic operations involving negative numbers.
Two’s complement is a method of representing signed integers in binary. To convert a positive number to
its negative counterpart in two's complement:
Another method for representing negative numbers is sign-magnitude. In sign-magnitude, the most
significant bit (MSB) is used to indicate the sign of the number:
Problem 1: Convert the following numbers into their 8-bit two’s complement representation:
1. -12
2. 3
3. -7
4. 15
1. -18
2. 23
3. -5
4. 16
1. 11111011
2. 10011001
3. 11100001
4. 11010100
Lab Manual: Number System Conversions
Problem 4: Decimal to Two’s Complement
1. 9
2. -23
3. 127
4. -56
Given the following hexadecimal color codes, identify the RGB values:
1. #FF6347 (Tomato)
2. #00FF00 (Lime)
3. #0000FF (Blue)
4. #FFFF00 (Yellow)
Write a program in Python (or any language of your choice) that takes an input number in one number
system (binary, decimal, octal, or hexadecimal) and converts it to all the other systems. For example, if
the input is a decimal number 56, the program should output:
Decimal: 56
Binary: 111000
Octal: 70
Hexadecimal: 38
The program should handle both positive and negative numbers and support two’s complement for
negative numbers in binary.