Back to Study Hub
Number Systems• 14 min read

Number Systems and Binary Codes: Binary, Octal, Hexadecimal, BCD and Gray Code

Master decimal, binary, octal and hexadecimal conversions, binary arithmetic, 1s and 2s complement subtraction, BCD, Excess-3, Gray code and parity for Wireless PSI and GPSC technical exams.

By MCQ Arena TeamUpdated June 24, 2026

Every digital circuit, microprocessor and communication system you will study reduces to one idea: representing information as patterns of 0s and 1s. Before you can analyse a counter, decode a memory address or read a fault code, you must be fluent in the number systems and binary codes that underpin all of digital electronics. This is the single most reliably tested foundation topic in technical recruitment papers.

This article builds that fluency from the ground up: positional weighting, fast conversions between decimal, binary, octal and hexadecimal, binary arithmetic, signed numbers with 1s and 2s complement, complement subtraction, the BCD (8421) and Excess-3 codes, Gray code with its binary conversions, a note on ASCII and parity, and the weighted-versus-non-weighted distinction. Expect 3 to 5 direct marks from this area in the Wireless PSI and GPSC technical syllabi, usually as quick one-mark recall and small conversion sums.

Positional Number Systems and the Idea of a Base

In a positional (place-value) number system the value of a digit depends on its position. Each system has a base (radix) r, and the digits allowed run from 0 to r-1. Moving one place left multiplies the weight by r.

N = dn-1rn-1 + ... + d1r1 + d0r0 + d-1r-1 + ...

d = digit, r = base/radix, position counts from 0 at the rightmost integer digit

Decimal uses base 10 (digits 0 to 9), binary base 2 (0, 1), octal base 8 (0 to 7) and hexadecimal base 16 (0 to 9 then A to F, where A=10 ... F=15). The rightmost integer digit is the least significant digit (LSB in binary) and the leftmost is the most significant digit (MSB). Octal and hex matter mainly because they are compact shorthand for long binary strings: one octal digit equals three bits and one hex digit equals four bits.

Exam tip: the largest value representable in n digits of base r is rn - 1, and the total number of distinct patterns is rn. For 8 bits that is 28 = 256 patterns, range 0 to 255.

The Master Conversion Table (0 to 15)

Memorising the first sixteen values across all four bases makes most conversion questions instant. The four-bit binary group is also the basis of hexadecimal and BCD.

DecimalBinary (4-bit)OctalHexadecimal
0000000
1000111
2001022
3001133
4010044
5010155
6011066
7011177
81000108
91001119
10101012A
11101113B
12110014C
13110115D
14111016E
15111117F

Inter-Conversions Between Bases

Any base to decimal

Multiply each digit by its positional weight and add. For example, binary 1011 = 1x8 + 0x4 + 1x2 + 1x1 = 11. Hex 2F = 2x16 + 15 = 47. Octal 17 = 1x8 + 7 = 15.

Decimal to any base

Use repeated division by the base for the integer part, reading remainders bottom-up. To convert 45 to binary: 45/2 gives remainders 1,0,1,1,0,1 read upward = 101101. For fractions, multiply by the base repeatedly and read the carried integer parts top-down.

Binary and octal or hex (the fast routes)

Group binary into threes from the binary point for octal, or fours for hex. Example: binary 11010110 grouped as 011 010 110 = octal 326; grouped as 1101 0110 = hex D6. To go back, expand each octal digit to 3 bits or each hex digit to 4 bits.

Common mistake: forgetting to pad with leading zeros when grouping, or grouping from the wrong end. Always group starting at the radix point and pad the far end if the final group is short.

Binary Arithmetic

Binary addition follows four rules: 0+0=0, 0+1=1, 1+0=1, and 1+1=10 (write 0, carry 1). Three ones give 11 (write 1, carry 1). Subtraction borrows in powers of two, and multiplication is repeated shift-and-add. Because addition is so simple, real hardware performs subtraction by adding a complement, which is why complements are central.

OperationExample (binary)Decimal check
Addition0101 + 0011 = 10005 + 3 = 8
Subtraction1010 - 0011 = 011110 - 3 = 7
Multiplication0110 x 0010 = 11006 x 2 = 12
Left shift (x2)0011 shifted = 01103 x 2 = 6

Exam tip: a left shift multiplies by 2 and a right shift divides by 2. This is faster than long multiplication when one operand is a power of two.

1s Complement, 2s Complement and Signed Numbers

The 1s complement of a binary number is formed by inverting every bit. The 2s complement is the 1s complement plus 1 (equivalently, copy bits from the right up to and including the first 1, then invert the rest). For an n-bit number, the 2s complement equals 2n minus the number.

2s complement = (2n - N) = (1s complement) + 1

N = original number, n = word length in bits

In signed 2s complement representation the MSB is the sign bit (0 = positive, 1 = negative). An 8-bit word covers -128 to +127. This scheme has a single representation of zero and lets the same adder handle positive and negative numbers, which is why almost every processor uses it.

DecimalSign-Magnitude (4-bit)1s Complement2s Complement
+5010101010101
-5110110101011
+0000000000000
-010001111does not exist
Range (4-bit)-7 to +7-7 to +7-8 to +7

Subtraction Using Complements

To compute A - B, add A to the complement of B.

  1. 2s complement method: add A and the 2s complement of B. If a final carry-out appears, discard it and the result is positive. If there is no carry, the result is negative and you must take the 2s complement of the answer to read its magnitude.
  2. 1s complement method: add A and the 1s complement of B. If a carry-out appears, add it back to the LSB (end-around carry); the result is positive. If no carry, take the 1s complement of the result for the negative magnitude.

Example (4-bit): 6 - 3. B = 3 = 0011, 2s complement = 1101. Add: 0110 + 1101 = 1 0011. Discard the carry, answer = 0011 = +3. Correct.

Common mistake: in the 2s complement method students add the carry back instead of discarding it. End-around carry belongs to the 1s complement method only.

BCD (8421), BCD Addition and Excess-3

Binary Coded Decimal (BCD), also called 8421 code, encodes each decimal digit as its own 4-bit binary group. So 59 in BCD is 0101 1001, not the pure binary 111011. BCD is weighted (weights 8,4,2,1) and wastes the six patterns 1010 to 1111, which are invalid in BCD.

BCD addition correction: add the BCD groups as binary; if any group exceeds 9 or produces a carry, add 0110 (6) to that group to skip the six invalid codes. Example: 5+5 = 0101+0101 = 1010, which is > 9, so add 0110 to get 1 0000 = BCD 10. Correct.

Excess-3 (XS-3) code is BCD plus 3 (add 0011 to each decimal digit). It is a non-weighted, self-complementing code: the 1s complement of an Excess-3 digit gives the Excess-3 code of its 9s complement, which simplifies decimal subtraction in older arithmetic hardware.

DecimalBCD (8421)Excess-3Gray code
0000000110000
1000101000001
2001001010011
3001101100010
4010001110110
5010110000111
6011010010101
7011110100100
8100010111100
9100111001101

Gray Code, ASCII and Parity

Gray code and conversions

Gray code is a non-weighted reflected code in which only one bit changes between consecutive values. This single-bit-change property eliminates spurious outputs in shaft encoders and reduces switching errors, and it is the natural ordering used in Karnaugh maps.

Binary to Gray: the MSB is copied unchanged; each next Gray bit is the XOR of adjacent binary bits. Gray to binary: copy the MSB; each next binary bit is the XOR of the previous binary bit with the current Gray bit. Example: binary 1011 to Gray = 1110; Gray 1110 back to binary = 1011.

gn-1 = bn-1; gi = bi+1 XOR bi

Binary to Gray, where the symbol denotes XOR; b is binary, g is Gray, MSB at index n-1

ASCII

ASCII is a 7-bit alphanumeric code representing 128 characters (letters, digits, punctuation, control codes). With a parity bit it fills a byte. It is an alphanumeric, non-weighted code, distinct from EBCDIC (8-bit, IBM).

Parity

A parity bit is an extra bit appended to make the total number of 1s even (even parity) or odd (odd parity). It detects any single-bit error but cannot correct it, and it misses double-bit errors. Parity is the simplest error-detection code on the syllabus.

Weighted vs Non-Weighted Codes

A weighted code assigns a fixed positional weight to each bit so the digit value is the weighted sum; examples are 8421 BCD, 2421 and 5211. A non-weighted code has no fixed positional weights; examples are Excess-3, Gray code and ASCII. Self-complementing codes such as 8421 are not, but 2421 and Excess-3 are.

CodeWeighted?Self-complementing?Key use
8421 (BCD)YesNoDecimal display, calculators
2421YesYesDecimal arithmetic
Excess-3NoYesDecimal subtraction hardware
GrayNoNoEncoders, K-maps
ASCIINoNoAlphanumeric data
Key Takeaways
  • Value of a digit is digit x base raised to its position; n bits give 2 to the power n patterns, range 0 to 2 to the power n minus 1.
  • Group binary in threes for octal and fours for hex; one octal digit is 3 bits, one hex digit is 4 bits.
  • 2s complement = 1s complement + 1; signed 2s complement has one zero and range minus 2 to the power n-1 to plus 2 to the power n-1 minus 1.
  • In 2s complement subtraction discard the final carry; in 1s complement subtraction add the end-around carry.
  • BCD addition: add 0110 to any group that exceeds 9 or generates a carry.
  • Gray code changes only one bit between neighbours; binary to Gray uses XOR of adjacent binary bits, MSB copied.
  • Weighted codes: 8421, 2421, 5211. Non-weighted: Excess-3, Gray, ASCII. Self-complementing: 2421 and Excess-3.

Practice MCQs

Q1. The hexadecimal number 2F is equal to which decimal value?

  • A.31
  • B.47
  • C.63
  • D.79

Correct Answer: B

Explanation: 2F = 2 x 16 + F(15) = 32 + 15 = 47. Hexadecimal digit F represents decimal 15.

Q2. How many distinct values can be represented using 8 bits?

  • A.128
  • B.255
  • C.256
  • D.512

Correct Answer: C

Explanation: n bits give 2 to the power n distinct patterns. 2 to the power 8 = 256 patterns, covering the range 0 to 255.

Q3. The 2s complement of the 4-bit binary number 0101 is:

  • A.1010
  • B.1011
  • C.0101
  • D.1101

Correct Answer: B

Explanation: 1s complement of 0101 is 1010; adding 1 gives 1011. This represents minus 5 in 4-bit signed 2s complement form.

Q4. In 1s complement subtraction, when a carry-out is generated from the MSB, you should:

  • A.Discard the carry
  • B.Add the carry back to the LSB
  • C.Complement the result
  • D.Set the sign bit to 1

Correct Answer: B

Explanation: The 1s complement method uses end-around carry: the carry-out is added back to the least significant bit, and the positive result is then read directly.

Q5. The BCD (8421) representation of decimal 27 is:

  • A.0010 0111
  • B.0001 1011
  • C.0010 1011
  • D.1011 0010

Correct Answer: A

Explanation: BCD encodes each decimal digit separately: 2 = 0010 and 7 = 0111, giving 0010 0111. Pure binary 11011 would be wrong here.

Q6. During BCD addition, a correction of 0110 is added to a 4-bit group when the group result is:

  • A.Equal to 9
  • B.Greater than 9 or produces a carry
  • C.Less than 6
  • D.An odd number

Correct Answer: B

Explanation: BCD has six unused codes (1010 to 1111). If a group exceeds 9 or carries out, adding 0110 (6) skips those invalid codes and restores valid BCD.

Q7. The Gray code equivalent of binary 1011 is:

  • A.1110
  • B.1101
  • C.1111
  • D.1001

Correct Answer: A

Explanation: Binary to Gray: copy MSB (1); then XOR adjacent binary bits: 1 XOR 0 = 1, 0 XOR 1 = 1, 1 XOR 1 = 0. Result is 1110.

Q8. Which of the following codes is both non-weighted and self-complementing?

  • A.8421 BCD
  • B.Gray code
  • C.Excess-3
  • D.ASCII

Correct Answer: C

Explanation: Excess-3 is non-weighted yet self-complementing: the 1s complement of an Excess-3 digit yields the Excess-3 code of its 9s complement. Gray is non-weighted but not self-complementing, and 8421 is weighted.

MA

MCQ Arena Team

Subject reviewers & exam mentors

This guide is written and fact-checked by the MCQ Arena editorial team — engineering graduates and competitive-exam mentors who build the question banks used on the platform. Every concept, formula and MCQ is cross-checked against standard textbooks and the latest Wireless PSI / GPSC exam pattern. Spotted an error or have a correction? Tell us — we update articles as syllabi and feedback come in.

Last reviewed and updated on June 24, 2026.

Put it into practice

Reading strategy is one thing — building it into instinct takes timed reps. Practise with daily timed mock tests on MCQ Arena.

Start practising free

Keep reading