UNIHIVE

Study Hub UNIPORT PHY 452

PHY 452 · Electronics

Number systems and codes

Binary, octal and hexadecimal, conversions, signed numbers and two's complement, BCD, Gray and ASCII codes.

Our notes

1 min read

Two-valued variables

Digital circuits work with signals of two levels: 1 (HIGH, true) and 0 (LOW, false). In 5 V TTL logic, HIGH is about 2 to 5 V and LOW about 0 to 0.8 V. Two levels are easy to tell apart, so digital signals resist noise.

Number systems

DecimalBinaryOctalHexadecimal
0000000
5010155
91001119
10101012A
15111117F
16100002010

Conversions

  • Decimal to binary: divide by 2 repeatedly and read the remainders from the last. Example: 45 → 101101 (32 + 8 + 4 + 1).
  • Binary to hexadecimal: group bits in fours from the right. 0010 1111 = 2F (hex) = 47 (decimal).
  • Binary to octal: group in threes.
  • Fractions: multiply by 2 repeatedly and take the integer parts.

Signed numbers

  • Sign-magnitude: leftmost bit is the sign; awkward for arithmetic.
  • One's complement: invert every bit.
  • Two's complement: invert every bit and add 1. Used in all computers because subtraction becomes addition.
  • Example: -6 in 8 bits: 6 = 00000110, invert 11111001, add 1 = 11111010.
  • An n-bit two's complement number covers -2^(n-1) to 2^(n-1) - 1 (8 bits: -128 to +127).

Binary arithmetic

0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (0 carry 1), 1 + 1 + 1 = 11. Subtraction A - B is A + (two's complement of B), ignoring the final carry.

Codes

  • BCD (8421): each decimal digit in 4 bits: 59 = 0101 1001. Used in displays and calculators.
  • Gray code: only one bit changes between successive numbers (0, 1, 11, 10, 110, ...); used in shaft encoders to avoid errors.
  • Excess-3: BCD + 3, self-complementing.
  • ASCII: 7-bit code for characters (A = 65 = 41 hex).
  • Parity bit: an extra bit making the number of 1s even (or odd), to detect single errors in transmission.

Exams usually ask

  • Convert numbers between bases.
  • Represent negative numbers in two's complement and perform binary subtraction.

Common mistake

Reading BCD as ordinary binary. 0101 1001 in BCD is 59, but as a binary number it is 89.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

No reading links here yet

Our team adds free books, videos and practice for each topic, and opens every link before it goes up.

All PHY 452 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.