Translate

Monday, January 1, 2018

Decimal conversion with Truth Tables and my first book review.

 I have been using Truth Tables to convert decimal numbers to binary, hexadecimal, and back again for the main purpose of knowing, and maybe applying it to ASCII description in code. This information is readily available to find on the Web; It is simple enough to do these calculations and it can be fun! For my first example the number 7 will be converted to Binary. First, I will want to write out the table with a value bigger than 7. Second, I will want to divide until there is no remainder. Table: 2^0=1, 2^1=2, 2^2=4, 2^3=8, now for the math, since 7 can not be divide by 8 our first digit is 0 since 7/8=0, 7/4=1 remainder 3, 3/2=1 remainder 1, 1/1=1 giving 0111. Another 32; 2^0=1, 2^1=2, 2^2=4, 2^=3=8, 2^4=16, 2^5=32 giving my Binary number of 10000 since 32 goes into 32 with no remainder our first digit is 1 followed by a zero for each place value or 5 zeros. Now, I would like to describe this process with Hexadecimal; number 3527, first I write my table to the first number larger than 3527 (16^0=1, 16^1=16, 16^2=256, 16^3=4096; knowing base 16 I'll divide 3527/4096=0, 3527/256=13 or D remainder 199, 199/16=12 or C remainder of 7 making Hexadecimal number 0DC7.  

 Truth Tables are fun in general when doing calculations of this nature. Easily applying it to any giving base (8^0=1, 8^1=8, 8^2=64, 8^3=512 so the decimal number 11 is Octal number 13 because 11/8=1 remainder 3 and 3/1=3 take our first digit 1 last 3 = 13). 

Converting a Binary to Decimal number is simple enough; for example 11010011, I will start with the first 8 values of the binary truth table because the Binary number has 8 digits: 2^0=0, 2^1=2, 2^2=4, 2^3=8, 2^4=16, 2^5=32, 2^6=64, 2^7=128. Now I will just add all the 1's up; 128+64+0+16+0+0+2+1=211. 

Hexadecimal to Decimal works in the same manner; for example 52a5, start with the truth table with as many place values as the number: 16^0=1, 16^1=16, 16^2=256, 16^3=4096. Starting with the last digit apply each value: 5*1=5, 10*16=160, 2*256=512, 5*4096=20480 5+160+512+20480=21,157   

 Last, I would like to mention a book I downloaded for my kindle, "The Absolute Beginner's Guide to Binary, Hex, Bits, and Bytes!"by Greg Perry. This short little book is a great read if you have a half hour. Greg explains basics of base 2 and how this is useful when working with computers. I enjoyed it so much, it inspired me to write up this post.     


Number Lines:

Hexadecimal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a(10), b(11), c(12), d(13), e(14), f(15), 10, 11, 12, 13...

Binary:0(0), 1(1), 10(2), 11(3), 100(4), 101(5), 110(6), 111(7), 1000(8), 1001(9), 1010(10), 1011(11), 1100(12), 1101(13), 1110(14)...


1 comment: