From jacobson@CNS.UNI.EDU Wed Oct 25 15:42:53 2000 Date: Wed, 25 Oct 2000 15:26:44 -0500 (CDT) From: Mark Jacobson To: 810-080-01@uni.edu, 810-080-02@uni.edu Subject: Base 16, hexadecimal and bc calculator... Noon MWF Question: What does 256 look like in base 16 (hexadecimal)? Recall that the base 16 digits set is {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}. Recall that the base 2 digits set is {0, 1} Here is what some numbers look like when the bc chaos.cns.uni.edu Unix calculator is used with obase=2 and obase=16 to see output in base 2 or base 16 - ---- <49 nova:~/web >bc obase=16 <---- Change the output base to base 16 instead of the default obase=10 setting (obase = decimal). 256 2 1 0 100 1 x 16 + 0 x 16 + 0 x 16 = 1 x 256 + 0 + 0 255 FF 15 x 16 + 15 x 1 obase=2 <---- Change the obase (output base) to base 2 binary 256 <---- This is input expression for bc calculator program. 100000000 <---- This is the output from the calculator software. 255 <---- Input expression 11111111 <---- Output result 15 <---- Input expression 1111 <---- Output results from bc program obase=16 <---- Change the obase to base 16 hexadecimal 1024 <---- Input 400 <---- Output is 1,024 converted to base 16 value. Not four hundred! 1023 2 1 0 3FF 3 x 16 + 15 x 16 + 15 x 16 = (3 x 256) + (15 x 16) + 15 <50 nova:~/web > ------------------------------------------------------------------------- We will use the bc calculator during the hands-on class to be scheduled for November sometime after all of the new computers are installed in the Wright 112 and Wright 339 labs. ------------------------------------------------------------------------- See your Wednesday, October 25th (Thursday, October 26th) hash table handout for an example of the usefulness of the bc calculator, with input redirection. ------------------------------------------------------------------------- 235 % 100 in bc language is 235 mod 100, so the output would be 35 the remainder of 35 235 / 100 in bc language is division, but integer division, so the 2 quotient is 2 2 ^ 10 is 2 to the 10th power, which is 1024 or 256 * 2 * 2 1024 obase=2 2 ^ 10 10000000000 <----- This is what 1024 looks like in binary. 1 followed by 10 0s 1023 1111111111 <----- The largest number that can be expressed with ten binary digits is 1,023 in base 10 and is 3FF in base 16. 1111111111 -3---F---F 3=11 F=1111 F=1111 3 F F 1111111111 33FFFFffff