Fall 2000

Lab 2 Pre-Lab: Base conversion

CS61C

Purpose:

This prelab focuses on base conversion. You will be required to practice the base conversion exercises before the lab and show all your work.

Lab policy:

Do all the exercises on your own or in a group before your lab time. But write up must be done individually and hand in your answers to your TA in the beginning of lab( this week you can turn it in by the end of the lab since the pre lab posted late ). Be sure to show your work.

Task: base converter

You should be able to convert numbers between any two bases.

There are some examples of base conversion between binary and decimal numbers. Of course there are many other ways of doing the base conversion.
Follow this example and practice on other bases.

  (1)   14_base10 to base 2 
 
  14_base10 = 2*7 + 0  ( notice remainder = 0 )
  7_base10  = 2*3 + 1   ( notice remainder = 1 )
  3_base10  = 2*1 + 1   ( notice remainder = 1 )
  1_base10  = 2*0 + 1   ( notice remainder = 1 )

  now write the remainders down and we have:
  14_base10 = 1110_base2


  (2)  1110_base2 to base 10

  1110_base2 = 1*2^3 + 1*2^2 + 1*2^1 + 0*2^0
  	     = 8_base10 + 4_base10 + 2_base10 + 0_base10
	     = 14_base10
  
Now practice the following on your own:

  • 1) 10111_base2 to base10
  • 2) AF12_base16 to base 8
  • 3) 127422_base8 to base 16
  • 4) 10111_base2 to base 7
  • 5) AF12_base16 to base 5 ( first convert AF12 to decimal )

Hints:

  • Sometimes it's easier to convert the number from its input base to base 10 first and then convert from base 10 to output base.
  • Write subscript _base* next to your number to keep track of the base of the number ( like in the examples above )
  • Use the examples above to check your code!

Feedback:

Please send your comments about the content and the format of this pre lab to: cs61c-tl@cory.eecs.berkeley.edu

created: 9/4/00 by Lan *^_^*