Week 1 Reading: Number Systems (pt. 2) - sullivaneg/TechJournal-SYS140 GitHub Wiki

Number Systems

In any of the number systems (decimal, binary, hexadecimal, etc) 0 is an important value. It counts as one of the digits.

3 rules of any number system

  • When you have used all your numbers you add a digit to the left and 0's to the right. ex) 999 + 1 = 1000
  • Then you keep adding to the right until you hit all the numbers, then increase the digit on the left by 1. ex) 1999 + 1 = 2000
  • When you reach the limit on both the left and the right, make them both 0 and add a 1 to the left. ex) 9999 + 1 =10000

Reading numbers: ex) Decimal 62302 = (6x10^4) + (2x10^3) + (3x10^2) + (0x10^1) + (2x10^0) ex) Binary 100101 = (1x2^5) + (0x2^4) + (0x2^3) + (1x2^2) + (0x2^1) + (1x2^0)

Hexadecimal notation:

  • A single hexadecimal digit can be made with 4 binary digits.

Converting Hexadecimal to Binary:

  • Note: I wanted to attempt to do this myself to better understand it so I used the same example from the article but wrote out the binary myself, then checked my work.
Hexadecimal 3 9 A 7 F 8
Binary 0011 1001 1010 0111 1111 1000

Converting Binary to Hexadecimal

  • Break binary # into bits, if the bit isn't 4 digits long, add 0's to the left until there's 4.
  • Same thing as above, I used the same example but did it myself and checked my work. 001001101110011110110101
Binary 0010 0110 1110 0111 1011 0101
Hexadecimal 2 6 E 7 B 5

Signed and Unsigned Numbers

  • Words: In a computer a word is data with a defined bit length. Many computers moved from 32 bit to 64 bit

ex) 100100 as a 32 bit word 0000 0000 0000 0000 0000 0000 0010 0100

  • The bit on the far left is the most significant bit and the bit on the far right is the least significant bit
  • With w bits the amount of numbers you can represent is 0 to 2^w - 1

Two's Complement encoding for signed #'s

  • Most computers use Two's complement for negative numbers.
  • Most significant bit has negative weight so all negative numbers have a 1 in that bit, this is known as the sign bit
  • When the sign bit is 1 it's negative, 0 is positive
  • With w bits the range of numbers is -2^w to 2^(w-1) - 1
  • Minimum value is -2^(w-1) : with 4 bits it's -8 because you can have a 1 in that far left slot
  • Maximum value with 4 bits is 7 because you can't have a 1 in that far left slot.

Zero Extension: If an unsigned # needs to be converted to a # w/ more bits, you add zeros to the left.

Sign Extension:

  • To convert a two's complement number to a certain bit size you add 1's to the left
  • Shortcut: convert 1's to 0's and 0's to 1's and then add 1 to the answer

Note: I had a hard time understanding WHY the numbers added up the same if you added a ton of 1's but I came to understand it like this -4(base 10) = 1111 1100 = -128 +64+32+16+8+4+0+0 = -128+124 = -4

Binary #'s and base systems as fast as possible:

  • A lot of this was review
  • The way the numbers are laid out is called "positional notation"