Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
26 views14 pages

Number System Conversions

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 14

Lab Manual: 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.

 Binary (Base-2) uses two symbols: 0 and 1.

 Decimal (Base-10) uses ten symbols: 0 to 9.

 Octal (Base-8) uses eight symbols: 0 to 7.

 Hexadecimal (Base-16) uses sixteen symbols: 0 to 9 and A to F.

Understanding number system conversions is essential in areas like computer science, programming, and
digital electronics.

1. Conversion between Binary and Decimal


1.1 Decimal to Binary Conversion:

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.

Steps for Decimal to Binary Conversion:

1. Divide the decimal number by 2.

2. Record the remainder.

3. Continue dividing the quotient by 2 until the quotient becomes 0.

4. The binary number is the sequence of remainders, written in reverse order.

Example: Convert 13 (decimal) to binary

 13 ÷ 2 = 6, remainder = 1

 6 ÷ 2 = 3, remainder = 0

 3 ÷ 2 = 1, remainder = 1

 1 ÷ 2 = 0, remainder = 1

Binary representation: 1101


Lab Manual: Number System Conversions
1.2 Binary to Decimal Conversion:

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.

Steps for Binary to Decimal Conversion:

1. Write down the binary number.

2. Assign each bit a power of 2, starting from 0 (rightmost bit).

3. Multiply each bit by the corresponding power of 2.

4. Sum the results to get the decimal number.

Example: Convert 1101 (binary) to decimal

 1×23=81 \times 2^3 = 81×23=8

 1×22=41 \times 2^2 = 41×22=4

 0×21=00 \times 2^1 = 00×21=0

 1×20=11 \times 2^0 = 11×20=1

Decimal representation: 8 + 4 + 0 + 1 = 13

2. Conversion between Decimal and Octal


2.1 Decimal to Octal Conversion:

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.

Example: Convert 35 (decimal) to octal

 35 ÷ 8 = 4, remainder = 3

 4 ÷ 8 = 0, remainder = 4

Octal representation: 43

2.2 Octal to Decimal Conversion:

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.

Example: Convert 43 (octal) to decimal

 4×81=324 \times 8^1 = 324×81=32

 3×80=33 \times 8^0 = 33×80=3


Lab Manual: Number System Conversions
Decimal representation: 32 + 3 = 35

3. Conversion between Decimal and Hexadecimal


3.1 Decimal to Hexadecimal Conversion:

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).

Example: Convert 254 (decimal) to hexadecimal

 254 ÷ 16 = 15, remainder = 14 (E in hex)

 15 ÷ 16 = 0, remainder = 15 (F in hex)

Hexadecimal representation: FE

3.2 Hexadecimal to Decimal Conversion:

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.

Example: Convert FE (hexadecimal) to decimal

 F×161=15×16=240F \times 16^1 = 15 \times 16 = 240F×161=15×16=240

 E×160=14×1=14E \times 16^0 = 14 \times 1 = 14E×160=14×1=14

Decimal representation: 240 + 14 = 254

4. Conversion Between Binary, Octal, and Hexadecimal


 Binary to Octal: Group the binary number into sets of three bits from right to left, then convert
each group into an octal digit.

 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:

Task 1: Decimal to Binary Conversion

Problem: Convert the following decimal numbers to binary:


Lab Manual: Number System Conversions
1. 56

2. 231

3. 1024

Task 2: Binary to Decimal Conversion

Problem: Convert the following binary numbers to decimal:

1. 101101

2. 11101101

3. 100010101

Task 3: Decimal to Octal Conversion

Problem: Convert the following decimal numbers to octal:

1. 72

2. 156

3. 205

Task 4: Octal to Decimal Conversion

Problem: Convert the following octal numbers to decimal:

1. 105

2. 232

3. 67

Task 5: Decimal to Hexadecimal Conversion

Problem: Convert the following decimal numbers to hexadecimal:

1. 123

2. 255

3. 789

Task 6: Hexadecimal to Decimal Conversion

Problem: Convert the following hexadecimal numbers to decimal:

1. 7F

2. 1A3

3. B2
Lab Manual: Number System Conversions
Practical Questions and Solutions:

Q1: Convert the decimal number 25 to binary.

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

Binary representation: 11001

Q2: Convert the binary number 101010 to decimal.

Solution:

 1×25=321 \times 2^5 = 321×25=32

 0×24=00 \times 2^4 = 00×24=0

 1×23=81 \times 2^3 = 81×23=8

 0×22=00 \times 2^2 = 00×22=0

 1×21=21 \times 2^1 = 21×21=2

 0×20=00 \times 2^0 = 00×20=0

Decimal representation: 32 + 0 + 8 + 0 + 2 + 0 = 42

Assignments for Students:

Assignment 1:

1. Convert the following decimal numbers to binary and hexadecimal:

o 1024

o 255

o 512

2. Convert the following binary numbers to decimal:

o 1110101

o 10101111
Lab Manual: Number System Conversions
Assignment 2:

1. Convert the following hexadecimal numbers to decimal and binary:

o 3F

o A5

o 7D

2. Convert the following octal numbers to binary:

o 67

o 124

Assignment 3:

1. Convert the following decimal numbers to octal and binary:

o 100

o 48

o 77

5. Conversion Between Binary, Octal, and Hexadecimal


5.1 Binary to Octal Conversion

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.

Steps for Binary to Octal Conversion:

1. Group the binary number into groups of 3 bits, starting from the right. If necessary, pad with
leading zeros.

2. Convert each group of 3 bits into its octal equivalent.

Example: Convert 1101011 (binary) to octal

 Group the binary digits into sets of 3 bits from right to left: 011 010 111

 Convert each group to octal:

o 011 → 3

o 010 → 2

o 111 → 7

Octal representation: 327


Lab Manual: Number System Conversions
5.2 Octal to Binary Conversion

To convert an octal number to binary, simply convert each individual octal digit into its 3-bit binary
equivalent.

Steps for Octal to Binary Conversion:

1. For each octal digit, write its binary equivalent using 3 bits.

2. Concatenate all the binary groups.

Example: Convert 327 (octal) to binary

 3 → 011

 2 → 010

 7 → 111

Binary representation: 011010111

5.3 Binary to Hexadecimal Conversion

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.

Steps for Binary to Hexadecimal Conversion:

1. Group the binary number into sets of 4 bits, starting from the right. If necessary, pad with
leading zeros.

2. Convert each group to its hexadecimal equivalent.

Example: Convert 1101011011 (binary) to hexadecimal

 Group the binary digits into sets of 4 bits: 1101 0110 1011

 Convert each group to hexadecimal:

o 1101 → D

o 0110 → 6

o 1011 → B

Hexadecimal representation: D6B

5.4 Hexadecimal to Binary Conversion

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:

1. For each hexadecimal digit, write its 4-bit binary equivalent.

2. Concatenate all the binary groups.

Example: Convert A5 (hexadecimal) to binary

 A → 1010

 5 → 0101

Binary representation: 10100101

5.5 Octal to Hexadecimal Conversion

To convert from octal to hexadecimal, the easiest way is to first convert the octal number to binary and
then from binary to hexadecimal.

Steps for Octal to Hexadecimal Conversion:

1. Convert the octal number to binary.

2. Then, convert the resulting binary number to hexadecimal.

Example: Convert 254 (octal) to hexadecimal

1. Convert 254 (octal) to binary:

o 2 → 010

o 5 → 101

o 4 → 100

Binary representation: 010101100

2. Convert 010101100 (binary) to hexadecimal:

o Group the binary number into sets of 4 bits: 0010 1011 00

o Convert each group to hexadecimal:

 0010 → 2

 1011 → B

 00 → 00 (pad with leading zeroes if necessary: 0000)

Hexadecimal representation: 2B0

5.6 Hexadecimal to Octal Conversion


Lab Manual: Number System Conversions
To convert from hexadecimal to octal, first convert the hexadecimal number to binary and then from
binary to octal.

Steps for Hexadecimal to Octal Conversion:

1. Convert the hexadecimal number to binary.

2. Then, convert the resulting binary number to octal.

Example: Convert B2 (hexadecimal) to octal

1. Convert B2 (hexadecimal) to binary:

o B → 1011

o 2 → 0010

Binary representation: 10110010

2. Convert 10110010 (binary) to octal:

o Group the binary number into sets of 3 bits from the right: 010 110 010

o Convert each group to octal:

 010 → 2

 110 → 6

 010 → 2

Octal representation: 262

6. Advanced Practice Problems


Problem 1: Binary to Hexadecimal Conversion

Convert the following binary numbers to hexadecimal:

1. 111101101

2. 1010111101

3. 110101101011

Problem 2: Hexadecimal to Binary Conversion

Convert the following hexadecimal numbers to binary:

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

Problem 4: Binary, Octal, and Hexadecimal Comparison

1. Convert 1101101 (binary) to both octal and hexadecimal.

2. Convert 35 (octal) to both binary and hexadecimal.

3. Convert F1 (hexadecimal) to both binary and octal.

Lab Tasks (Advanced)

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.).

Task 3: Practical Applications

1. Use number system conversions in a programming language such as Python to automate these
conversions. Write a program that:

o Converts decimal numbers to binary, octal, and hexadecimal.

o Converts binary numbers to decimal, octal, and hexadecimal.

o Converts octal and hexadecimal numbers to decimal, binary, and each other.

Assignments for Students:

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

7. Applications of Number System Conversions

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.

7.1 Applications in Digital Systems and Electronics

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.

7.2 Memory Addresses and Data Representation

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.

7.3 Networking and IP Addressing

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:

 An IPv4 address such as 192.168.1.1 is actually a binary number:


11000000.10101000.00000001.00000001. It’s often easier for humans to read and manage in
decimal.

7.4 Color Representation in Graphics

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).

8. Understanding Signed Number Representations

In computing, negative numbers are often represented using two’s complement notation in binary. This
system allows for efficient arithmetic operations involving negative numbers.

8.1 Two’s Complement Representation:

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:

1. Write the number in binary.

2. Invert all the bits (flip 0s to 1s and 1s to 0s).

3. Add 1 to the result.

Example: Convert -5 to 8-bit two’s complement:

 First, write 5 in binary: 00000101 (for 8 bits).

 Invert the bits: 11111010.

 Add 1: 11111010 + 1 = 11111011.


Lab Manual: Number System Conversions
Result: -5 in 8-bit two’s complement is 11111011.

8.2 Sign-Magnitude Representation:

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:

 0 for positive numbers.

 1 for negative numbers.

Example: Convert -5 to sign-magnitude:

 Write 5 in binary: 00000101 (for 8 bits).

 In sign-magnitude, the MSB (leftmost bit) is set to 1 to indicate negative: 10000101.

Result: -5 in sign-magnitude representation is 10000101.

9. Additional Exercises and Problems

Problem 1: Convert the following numbers into their 8-bit two’s complement representation:

1. -12

2. 3

3. -7

4. 15

Problem 2: Sign-Magnitude Conversion

Convert the following decimal numbers to their 8-bit sign-magnitude representation:

1. -18

2. 23

3. -5

4. 16

Problem 3: Two’s Complement to Decimal

Convert the following 8-bit two’s complement binary numbers to decimal:

1. 11111011

2. 10011001

3. 11100001

4. 11010100
Lab Manual: Number System Conversions
Problem 4: Decimal to Two’s Complement

Convert the following decimal numbers to 8-bit two’s complement:

1. 9

2. -23

3. 127

4. -56

Problem 5: Hexadecimal Color Codes

Given the following hexadecimal color codes, identify the RGB values:

1. #FF6347 (Tomato)

2. #00FF00 (Lime)

3. #0000FF (Blue)

4. #FFFF00 (Yellow)

10. Programming Challenge: Number System Conversion Tool

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.

You might also like