0% found this document useful (0 votes)
4 views1 page

Week 4 Exercise

The document outlines exercises for a computer science course, focusing on conversions between binary, decimal, and hexadecimal representations, as well as 2's complement. It includes programming tasks such as checking for prime numbers, generating Fibonacci sequences, and creating random integers with specific conditions. Additionally, it references an algorithm from previous course notes for implementation.

Uploaded by

Khant Htoo Thwin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Week 4 Exercise

The document outlines exercises for a computer science course, focusing on conversions between binary, decimal, and hexadecimal representations, as well as 2's complement. It includes programming tasks such as checking for prime numbers, generating Fibonacci sequences, and creating random integers with specific conditions. Additionally, it references an algorithm from previous course notes for implementation.

Uploaded by

Khant Htoo Thwin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CMPT120 J.

Ye
Week 4 Exercise
(Solution will not be provided)

1. Convert among 8-bit unsigned binary, decimal and hexadecimal representations of integers a and b:

unsigned binary decimal hexadecimal

a 1111 1111

b 43

2. Convert among decimal and 8-bit 2’s complement representations of integers a and b:

decimal 2’s complement

a -58

b 1000 0000

3. Write a program that reads from keyboard a positive integer N and output whether N is a prime number.

4. Write a program that prints the first 30 numbers of Fibonacci sequence on one line. The Fibonacci sequence is as
follows:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34 …
i.e. first two numbers are 0 and 1, each number after that is equal to the sum of the two numbers that precede it. For
example, the third number in the sequence is equal to the sum of the first and second number, the fourth number is
equal to the sum of the second and third number, and so on …

5. Write a program that repeatedly generates and prints random integers in the range [1, 100]. The program must
stop when the distance between two successive printed values is less than 5. For example:
-- The program can possibly output this: 76 42 45
-- The program can possibly output this: 43 77 94 54 66 64

6. Implement the Algorithm Example #1 on slide #29 in Week 1 Notes

You might also like