Base to Base conversion

Convert from any base to base 10.

Base 2, base 8, base 16, base 10.
binary, octal, hex, decimal.
Digits go from 1 to (Base-1); Hexadecimal uses A..F for extra digits.
0..1
0..7
0..9
0..9,A,B,C,D,E,F
0	0000
1	0001
2	0010
3	0011
4	0100
5	0101
6	0110
7	0111
8	1000
9	1001
A	1010
B	1011
C	1100
D	1101
E	1110
F	1111

Numbers in base two are digits times powers of 2.
101=4*1+2*0+1*1=5
101101=1*32+0*16+1*8+1*4+0*2+1

Convert from base 2 to base 10.
101101 base 2
Start with the most significant digit
(start with 0 and add most significant digit)
1
multiply by base
add next digit 1*2+0=2
2
multiply by base 2*2+1=5
add next digit 
5
multiply by base 5*2+1=11
add next digit
11
multiply by base 11*2+0=22
add next digit
22
multiply by base 22*2+1=45
add next digit
45
When last digit is added, done
101101 base 2 = 45 base 10

Convert from base 8 to base 10.
123 base 8
(start with 0 and add most significant digit)
multiply by base 
add next digit	1
multiply by base 1*8+2=10
add next digit
10
multiply by base 10*8+3=83
add next digit
83

123 base 8 is 83 base 10

Convert from base 16 to base 10.

0ABCD
multiply by base 
add next digit
10

multiply by base 10*16+11
add next digit
171

multiply by base 171*16+12 
2748
add next digit

multiply by base 2748*16+13
add next digit
43981

Convert from base 10 to base 16.

Divide the number by the base, set remainder as LEAST significant digit
(or, next last significant digit)
43981/16= 2748 remainder 13
2748/16 = 171 remainder 12
171/16 = 10 remainder 11
10/16 = 0 remainder 10

So 43981 base 10 is 0ABCD hex.

To convert from base 8 to base 2:
(simpler because 8 is 2*2*2)

765
7*64+6*8+5
111110101

To convert from base 2 to base 16:
(simpler because 16 is 2*2*2*2)
Group digits by FOUR bits starting from the LEAST significant digit
0001 1111 0101
convert each 4 bits to a hex digit
1F5

To convert from base 16 to base 2:
convert each Hex digit startin gwith LEAST significant digit into 4 bits.

000111110101

To convert from base 2 to base 8:
Group digits by THREE bits starting from the LEAST significant digit
000 111 110 101
0765 in octal

0765 base 8

Converting 0765 octal to base 10:
Start with the most significant digit
(start with 0 and add most significant digit)
7
multiply by base	7*8+6
add next digit 
62
multiply by base	62*8+5
add next digit 
480+16+5=501

to convert from base 10 to base 8
divide by base, remainder is (next) least significant digit

501/8 62 remainder 5
62/8  7  remainder 6
7/8   0 remainder  7

765 base 8

Practice conversion hexadecimal to base 10:

111 base 16
multiply by base	
add next digit 
1
multiply by base	
add next digit 		1*16+1=17
17
multiply by base	
add next digit		17*16=272+1=273 

273 base 10

to convert from base 10 to base 16

divide by base, remainder is (next) least significant digit
273/16=17 remainder 1
17/16 =1 remainder 1
1/16 = 0 remainder 1

111 base 16

CONSIDER THE FOLLOWING:
ADD these two numbers in a 16 bit word:

1234 hex
edcc  hex
_____
0000 hex
Because it is a 16 bit word the high end CARRY has no where to go.
CARRY IS DROPPED
(Carry flag may be set)
Which makes EDCC really -1234

1234
0001 0010 0011 0100 
flip every bit
1110 1101 1100 1011
add 1
1110 1101 1100 1100
EDCC

That's how subtraction works on many machines.

Computer Representation of Information

Bits are not always numbers.
(And if they are numbers, they can be variable length, positive or negative, integer or floating point.)
The can also be, FOR EXAMPLE:
ASCII code
	Taking 8 bits at a time, look up the character in www.asciitable.com
Machine language instruction
	(Depends on your machine; 
	Op code, address, big versus little endian)

IMPORTANT:
The Operating System must be able to determine how to interpret a series of bits is a word.
How can it do that?