Positional numeral system

The value of the number (Note that represents a sequence of digits, not multiplication) is

  • is the basis (or radix)

  • is the set of symbols ()

  • is the number of digits to the left of the radix point (integer part)

  • is the number of digits to the right of the radix point (fractional part)

  • Binary

  • Octal

  • Decimal

  • Hexadecimal

Bit numbering

  • bit (b) is the smallest unit of data in a computer

  • Byte (B) is 8 bits

    • Nibble is 4 bits
  • Word is the natural unit of data used by a particular processor design, (in our course, it is 32 bits=4 bytes)

    • Halfword is 16 bits
  • Least significant bit (LSB) is the rightmost bit

  • Most significant bit (MSB) is the leftmost bit

Signed numbers

Sign–magnitude

  • if is a positive number, then is the negative of that number
  • the most significant bit is the sign bit
  • the range is to

One’s complement

  • the range is to
  • the negative of a number is obtained by inverting all bits
    • example:

Two’s complement

  • the range is to
  • If is a positive number, then we can find its negative by:
    • invert (flip) each bit (One’s complement) and add 1 to the result:
      • example:
    • subtract from :
      • example:

signed binary numbers

4-bit

BinaryUnsignedTwo’s complementSign–magnitudeOne’s complement
00000000
00011111
00102222
00113333
01004444
01015555
01106666
01117777
10008-8-0-7
10019-7-1-6
101010-6-2-5
101111-5-3-4
110012-4-4-3
110113-3-5-2
111014-2-6-1
111115-1-7-0

8-bit

BinaryUnsignedTwo’s complementSign–magnitudeOne’s complement
000000000000
000000011111
01111110126126126126
01111111127127127127
10000000128-128-0-127
10000001129-127-1-126
11111110254-2-126-1
11111111255-1-127-0

Conversion

Decimal to any base

Converting the integral part
// integer n in base 10 to base b
while n>0
	divide n by b to get quotient and remainder;
	append remainder to the left of the result;
	n=quotient;
Converting the fractional part
// fractional part n in base 10 to base b
while n>0
	multiply n by b to get integer part and fractional part;
	append integer part to the right of the result;
	n=fractional part;

// note: the fractional part may never become zero, stop when the desired precision is reached

Binary–hexadecimal conversion

4 binary digits can be represented by 1 hexadecimal digit

Binary–octal conversion

3 binary digits can be represented by 1 octal digit

Octal–hexadecimal conversion

we can convert octal to binary and then binary to hexadecimal or vice versa

Nonpositional numeral system