Question.5
What is the correct 2's complement of the 5-bit binary number 10110?
Digital electronics processes information using separate or discrete values.
The word digital comes from digit, which means a number symbol.
Digital circuits normally use two logic levels:
0 – LOW1 – HIGHPositive and Negative Logic
Logic defines how voltage levels represent binary values.
Table 1: Logic Conventions
| Logic Type | HIGH Voltage | LOW Voltage |
|---|---|---|
| Positive logic | 1 | 0 |
| Negative logic | 0 | 1 |
Positive logic is used more widely in digital circuits.
Importance of Number Systems
Number systems are used to:
A number system uses a fixed set of digits and a base.
The value of each digit depends on its position:
Value = Digit × BaseᵖᵒˢⁱᵗⁱᵒⁿTable 2: Common Number Systems
| Number System | Base | Digits | Sequence Example | Data Example |
|---|---|---|---|---|
| Decimal | 10 | 0 to 9 | 8, 9, 10, 11 | 45₁₀ |
| Binary | 2 | 0, 1 | 0, 1, 10, 11, 100 | 101101₂ |
| Octal | 8 | 0 to 7 | 6, 7, 10, 11 | 55₈ |
| Hexadecimal | 16 | 0 to 9, A to F | E, F, 10, 11 | 2D₁₆ |
In hexadecimal:
A = 10B = 11C = 12D = 13E = 14F = 15
The same value will be used in all examples:
45₁₀ = 101101₂ = 55₈ = 2D₁₆
Decimal to Binary
Repeatedly divide the decimal number by 2.
Write the remainders from bottom to top.
Example: Convert 45₁₀ to Binary
| Division | Quotient | Remainder |
|---|---|---|
| 45 ÷ 2 | 22 | 1 |
| 22 ÷ 2 | 11 | 0 |
| 11 ÷ 2 | 5 | 1 |
| 5 ÷ 2 | 2 | 1 |
| 2 ÷ 2 | 1 | 0 |
| 1 ÷ 2 | 0 | 1 |
Reading upward:
45₁₀ = 101101₂
Decimal to Octal
Repeatedly divide the decimal number by 8.
45 ÷ 8 = 5, remainder 5
5 ÷ 8 = 0, remainder 5
Therefore:
45₁₀ = 55₈
Decimal to Hexadecimal
Repeatedly divide the decimal number by 16.
45 ÷ 16 = 2, remainder 13
13 = D
Therefore:
45₁₀ = 2D₁₆
Table 3: Decimal Conversion Summary
| Required System | Division Base | Result for 45₁₀ |
|---|---|---|
| Binary | 2 | 101101₂ |
| Octal | 8 | 55₈ |
| Hexadecimal | 16 | 2D₁₆ |
Binary to Decimal
Multiply every binary bit by its positional weight.
101101₂
= 1×2⁵ + 0×2⁴ + 1×2³ + 1×2² + 0×2¹ + 1×2⁰
= 32 + 8 + 4 + 1
= 45₁₀Binary to Octal
Group binary bits into sets of 3, starting from the right.
101 101
101₂ = 5₈101₂ = 5₈Therefore:
101101₂ = 55₈
Binary to Hexadecimal
Group binary bits into sets of 4, starting from the right.
Add leading zeros when required:
0010 1101
0010₂ = 2₁₆1101₂ = D₁₆Therefore:
101101₂ = 2D₁₆
Table 4: Binary Conversion Summary
| Required System | Method | Result for 101101₂ |
|---|---|---|
| Decimal | Positional weights | 45₁₀ |
| Octal | Group into 3 bits | 55₈ |
| Hexadecimal | Group into 4 bits | 2D₁₆ |
Octal to Binary
Replace each octal digit with its 3-bit binary value.
5₈ = 101₂
Therefore:
55₈ = 101 101₂
55₈ = 101101₂
Octal to Decimal
Multiply every digit by its positional weight.
55₈
= 5×8¹ + 5×8⁰
= 40 + 5
= 45₁₀Octal to Hexadecimal
First convert octal to binary:
55₈ = 101101₂
Group the binary value into 4 bits:
0010 1101
Therefore:
55₈ = 2D₁₆
Table 5: Octal Conversion Summary
| Required System | Method | Result for 55₈ |
|---|---|---|
| Binary | Replace each digit with 3 bits | 101101₂ |
| Decimal | Positional weights | 45₁₀ |
| Hexadecimal | Octal → Binary → Hexadecimal | 2D₁₆ |
Hexadecimal to Binary
Replace each hexadecimal digit with its 4-bit binary value.
2₁₆ = 0010₂D₁₆ = 1101₂Therefore:
2D₁₆ = 0010 1101₂
Removing leading zeros:
2D₁₆ = 101101₂
Hexadecimal to Decimal
Multiply every digit by its positional weight.
2D₁₆
= 2×16¹ + 13×16⁰
= 32 + 13
= 45₁₀Hexadecimal to Octal
First convert hexadecimal to binary:
2D₁₆ = 00101101₂
Group the bits into sets of 3:
00 101 101
101₂ = 5₈
Therefore:
2D₁₆ = 55₈
Table 6: Hexadecimal Conversion Summary
| Required System | Method | Result for 2D₁₆ |
|---|---|---|
| Binary | Replace each digit with 4 bits | 101101₂ |
| Decimal | Positional weights | 45₁₀ |
| Octal | Hexadecimal → Binary → Octal | 55₈ |
Table 7: Number-System Conversion Methods
| From | To | Method |
|---|---|---|
| Decimal | Binary, Octal or Hexadecimal | Repeated division by required base |
| Binary | Decimal | Add positional weights |
| Binary | Octal | Group into 3 bits |
| Binary | Hexadecimal | Group into 4 bits |
| Octal | Binary | Replace each digit with 3 bits |
| Hexadecimal | Binary | Replace each digit with 4 bits |
| Octal | Hexadecimal | Convert through binary |
| Hexadecimal | Octal | Convert through binary |
Signed binary numbers represent both positive and negative values.
The most significant bit is used as the sign bit:
0: Positive1: NegativeThe remaining bits represent the value.
Sign-Magnitude Range
For an n-bit sign-magnitude number:
Range = −(2ⁿ⁻¹ − 1) to +(2ⁿ⁻¹ − 1)
For 4 bits:
Range = −7 to +7
Sign-magnitude has two zero values:
0000 = +01000 = −0
Binary addition follows four basic rules.
Table 8: Binary Addition Rules
| Addition | Sum | Carry |
|---|---|---|
0 + 0 | 0 | 0 |
0 + 1 | 1 | 0 |
1 + 0 | 1 | 0 |
1 + 1 | 0 | 1 |
1 + 1 + 1 | 1 | 1 |
Example
1011
+ 0110
-------
100011011₂ = 11₁₀
0110₂ = 6₁₀
10001₂ = 17₁₀
The 1's complement of a binary number is found by inverting every bit.
0 to 1.1 to 0.Example
Original number:
0101
Invert all bits:
1010
Therefore, in 4-bit 1's complement:
+5 = 0101−5 = 1010Limitation
1's complement has two representations of zero:
00001111Addition may also require an end-around carry.
The 2's complement is found in two steps:
1.Example: Find −5
Positive 5:
0101
1's complement:
1010
Add 1:
1010
+ 0001
------
1011Therefore:
−5 = 1011
Range
For an n-bit 2's complement number:
Range = −2ⁿ⁻¹ to +(2ⁿ⁻¹ − 1)
For 4 bits:
Range = −8 to +7
Benefits
Table 9: Signed Binary Representations
| Representation | +5 | −5 | 4-Bit Range | Zero Values |
|---|---|---|---|---|
| Sign-magnitude | 0101 | 1101 | −7 to +7 | Two |
| 1's complement | 0101 | 1010 | −7 to +7 | Two |
| 2's complement | 0101 | 1011 | −8 to +7 | One |
Binary subtraction uses borrowing, similar to decimal subtraction.
Basic rules:
0 − 0 = 01 − 0 = 11 − 1 = 00 − 1 requires a borrowAfter borrowing:
10₂ − 1₂ = 1₂
Example
10110
- 00101
--------
1000110110₂ = 22₁₀
00101₂ = 5₁₀
10001₂ = 17₁₀
Subtraction Using 2's Complement
Binary subtraction can be changed into addition:
A − B = A + 2's complement of B
Example: 10110 − 00101
Step 1: Find 2's Complement of 00101
1's complement:
11010
Add 1:
11011
Step 2: Add It to 10110
10110
+ 11011
--------
1 10001Discard the final carry:
10001
Therefore:
10110₂ − 00101₂ = 10001₂
Result Rule
Binary codes represent numbers, characters or changing states using binary bits.
Gray code is a binary code in which two consecutive values differ by only one bit.
It is also called a unit-distance code.
Example
| Decimal | Binary | Gray |
|---|---|---|
| 0 | 000 | 000 |
| 1 | 001 | 001 |
| 2 | 010 | 011 |
| 3 | 011 | 010 |
Properties
Applications
BCD means Binary-Coded Decimal.
Each decimal digit is represented separately using four binary bits.
BCD normally uses the 8421 weighted code.
Example
Decimal value:
59
5 = 01019 = 1001Therefore:
59₁₀ = 0101 1001 in BCD
BCD 1010 to 1111 are invalid decimal-digit codes.
Properties
Applications
Excess-3 represents each decimal digit after adding 3 to it.
Example
Convert decimal 59:
For digit 5:
5 + 3 = 8 = 1000₂
For digit 9:
9 + 3 = 12 = 1100₂
Therefore:
59₁₀ = 1000 1100 in Excess-3
Properties
0011.Applications
ASCII means American Standard Code for Information Interchange.
It represents:
Standard ASCII uses 7 bits.
Examples
A = 65₁₀ = 1000001₂a = 97₁₀ = 1100001₂0 = 48₁₀ = 0110000₂Properties
Applications
Table 10: Binary Code Comparison
| Code | Main Purpose | Type | Example | Main Application |
|---|---|---|---|---|
| Gray | Represent changing positions | Non-weighted | Decimal 2 = 011 | Rotary encoders |
| BCD | Represent decimal digits | Weighted 8421 | Decimal 59 = 0101 1001 | Displays and calculators |
| Excess-3 | Represent decimal digits with offset | Non-weighted | Decimal 59 = 1000 1100 | Decimal arithmetic |
| ASCII | Represent characters | Character code | A = 1000001 | Text communication |