---
title: "39 to Gray/Excess-3 and 2's complement addition"
subject: "Digital Logic"
chapter: 1
key: "semester_3/digital_logic:convert-39-gray-excess3-addition"
source: https://www.bctengineer.com/q/semester_3/digital_logic/convert-39-gray-excess3-addition
site: BCT Engineering
---

# 39 to Gray/Excess-3 and 2's complement addition

Digital Logic · Chapter 1: Introduction

- Asked in: 2081 Baisakh, 2+2+3 marks
- Video: [Lec-8: BCD, Excess-3 Code & Conversion with example](https://www.youtube.com/watch?v=UgU5Og9Umak) — Gate Smashers
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_3/digital_logic/convert-39-gray-excess3-addition
- Whole chapter: https://www.bctengineer.com/md/semester_3/digital_logic/chapter-1

## Question

Convert decimal 39 into Gray code and Excess-3 code. Use 2's complement method to perform the following addition (-28+17)₁₀.

## Short answer

39 in Gray: binary 100111, Gray = 1 then XOR adjacent: 1,0,1,0,0 → 110100. Excess-3: 3→0110, 9→1100 → 0110 1100. (-28+17) in 8-bit 2's complement: -28 = 11100100, +17 = 00010001, sum = 11110101, which is -11.

## Answer

#### Decimal 39 to Gray code
First convert to binary by repeated division by 2:

| Division | Quotient | Remainder |
|---|---|---|
| 39 ÷ 2 | 19 | 1 |
| 19 ÷ 2 | 9 | 1 |
| 9 ÷ 2 | 4 | 1 |
| 4 ÷ 2 | 2 | 0 |
| 2 ÷ 2 | 1 | 0 |
| 1 ÷ 2 | 0 | 1 |

Reading upwards: $(39)_{10} = (100111)_2$.

Binary to Gray (keep MSB, then XOR adjacent bits):

```text
 Binary : 1   0   0   1   1   1
          |  / \ / \ / \ / \ /
 Gray   : 1   1   0   1   0   0
```

$G = 1,\ 1\oplus0=1,\ 0\oplus0=0,\ 0\oplus1=1,\ 1\oplus1=0,\ 1\oplus1=0$

**Answer: $(39)_{10} = (110100)_{Gray}$**

#### Decimal 39 to Excess-3
Add 3 to each digit: 3 + 3 = 6 → 0110; 9 + 3 = 12 → 1100.

**Answer: $(39)_{10} = (0110\ 1100)_{XS-3}$**

#### (−28) + (17) using 2's complement (8-bit)
- $+28 = 0001\ 1100$
- 1's complement: $1110\ 0011$; add 1 → $-28 = 1110\ 0100$
- $+17 = 0001\ 0001$

```text
    1110 0100   (-28)
  + 0001 0001   (+17)
  -----------
    1111 0101   no end carry
```

No end carry, so the result is negative and in 2's complement form. Take the 2's complement to find its magnitude: $0000\ 1010 + 1 = 0000\ 1011 = 11$.

**Answer: $(-28) + 17 = 1111\ 0101_2 = (-11)_{10}$**

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is (39) decimal in binary?
   A. 110011
   B. 101110
   C. 100111
   D. 100101
   Answer: C. 39 = 32 + 4 + 2 + 1 = 100111. (Key point: Decimal to binary)

2. What is 100111 in Gray code?
   A. 100111
   B. 111000
   C. 110111
   D. 110100
   Answer: D. Keep MSB 1, then XOR adjacent bits: 1,1,0,1,0,0. (Key point: Binary to Gray)

3. What is -28 in 8-bit 2's complement?
   A. 1110 0100
   B. 1110 0011
   C. 1001 1100
   D. 0001 1100
   Answer: A. +28 = 0001 1100; invert gives 1110 0011; add 1 gives 1110 0100. (Key point: 2's complement)

4. -28 + 17 gives 1111 0101 with no end carry. How is the answer read?
   A. Positive 245
   B. Negative; take 2's complement to get magnitude 11, so -11
   C. Positive 11
   D. Negative; magnitude is 10
   Answer: B. No end carry and MSB 1 mean a negative 2's complement result; its complement is 0000 1011 = 11. (Key point: Interpreting result)

## Related in Digital Logic

- [Gray→BCD, decimal→Excess-3 and 2's complement addition](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Agray-bcd-excess3-twos-addition) — Digital Logic, chapter 1
- [39 to binary/hex and 2's complement addition](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Aconvert-39-binary-hex-addition) — Digital Logic, chapter 1
- [Convert (17)₁₀ to Gray](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Aconvert-17-gray) — Digital Logic, chapter 1
- [Convert (17)excess-3 to BCD](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Aconvert-17-excess3-bcd) — Digital Logic, chapter 1
- [Convert (10101)gray to decimal](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Aconvert-gray-10101-decimal) — Digital Logic, chapter 1
- [Gray vs binary code, convert (10110)₂ to Gray](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Agray-vs-binary-convert-10110) — Digital Logic, chapter 1
