Monash University > CSSE > CSE1303 > Part A> Pracs > Prac A3

CSE1303 Computer Science
Semester 2, 2003
Part A
Prac A3 : Dynamic Memory

This prac covers material from lectures A06, B04 and B05 and Tutorial A3.

Project

To write a program which performs various operations on binary numbers.

Background:

In this prac we will represent a binary number as an array of char, where each element is either a '0' or '1'.
(This is a very inefficient representation in terms of space and a more efficient representation would be to represent the number as an array of unsigned char and use bitwise operations - not implemented in this prac).
Note: the array containing the binary number is NOT a string, it does not contain '\0'.

The binary operations we will consider in this prac are:

One's complement (also known as bitwise not) changes every '0' to '1', and every '1' to '0'.
Left Shift by n, shifts all the bits left by n places, filling vacated bits with '0'. This is equivalent to multiplication by 2n.
Right Shift by n, removes the first n-bits. This is equivalent to integer division by 2n.
(Note: always assume that n is a positive integer in this prac.)

For example, consider the following binary number:

The one's complement of this binary number is:

and when we left shift it by 3 and right shift it by 5 we obtain, respectively:

Preparation (3 marks if completed before class)


Question 1: (3 marks)


Question 2: (4 marks)


Advanced Questions: (2 marks)


[ Top | Home ]

Last modified: Thursday 26 June 2003 14:42:12