Positional numeral system

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

  • basis (or radix)

  • 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
  • two’s complement:
    • if is a positive number (where is the leftmost 1 bit), then is the negative of that number
    • the range is to
    • inverse of number in two’s complement:
      • method 1

4-bit signed binary numbers

BinaryUnsignedSign–magnitudeTwo’s complement
0000000
0001111
0010222
0011333
0100444
0101555
0110666
0111777
10008-0-8
10019-1-7
101010-2-6
101111-3-5
110012-4-4
110113-5-3
111014-6-2
111115-7-1

8-bit Two’s complement

BinaryUnsignedTwo’s complement
0000000000
0000000111
01111110126126
01111111127127
10000000128-128
10000001129-127
11111110254-2
11111111255-1

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

Any base to decimal conversion

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