CS1101: Laboratory 12(a)

Converting from Decimal to Binary

Academic Year 2006-2007

Lecturer: Dr. Barry O'Sullivan
Department of Computer Science
University College Cork

b.osullivan@cs.ucc.ie


Objective of this Lab

The objective of this lab is to ensure that students can implement decimal to binary conversion in Java using the successive halving method.


Tasks

Decimal to Binary Conversion

Write a program called Converter.java that takes a positive decimal integer as input and prints out its representation in binary represented as a string. You should use successive halving to perform the conversion.

The successive halving method consists of dividing the given number by 2 until the number 0 has been reached. The remainders are used to construct the equivalent binary number. See Figure 1: for an example.


Figure 1: An example of converting from decimal to binary using halving.

Submission

To submit your assignment please put your program in a Java file called Converter.java. To submit it, type the following from the command prompt from one of the lab machines:

cs1101submit Converter.java
The submission deadline is 5pm on Friday 23rd of March.


b.osullivan@cs.ucc.ie

Return to the CS1101 Home Page