You are on page 1of 6

Antonio Johnson “Straight A’s”

CAPE COMPUTER SCIENCE UNIT 1 CLASS (April 2018)


Name:
Date:

Module 1 Objective 3

1. Converting Decimal to Binary

Convert 2910 to binary using a 6-bit register


Try

11710 to binary using an 8-bit


2 29 register
2 14 1
2 7 0
2 3 1
2 1 1
2 0 1

Answer: 011101

2. Converting Binary to Decimal Try

Convert 0111012 to decimal 110112 to decimal

3. One’s Complement

One’s complement uses a sign bit. In order to calculate the one’s complement of a number:

a) Write down the sign bit (1 for negative, 0 for positive)


b) Write down the positive equivalent of the number
c) Flip all the bits following the sign bit.

Eg: -3 in one’s complement using 4 bits. (One’s Complement can only be used to represent)

Sign bit =1 negative), +3 in decimal =011, flip all bits following the sign bit= 1100

Try this: Find the ones complement of -5 using 4 bits (May/June 2013 Question (1)(b)(ii))

4. Two’s Complement

To represent a negative number in two’s complement:

a) Write down the sign bit


b) Calculate the ones complement
c) Add one to the ones complement

Eg. -3 in two’s complement using 4 bits is

Sign bit= 1, ones complement= 1100, add one to the one’s compliment= 1101

Try this: Find the two’s complement of -5 using 4 bits (May/June 2013 Question (1)(b)(iii))

Try this: Find the 8-bit two’s complement of -21 (May/June 2015 Question (1)(e))

Try this: Calculate the 4-bit two’s complement of -7 (May/June 2014 Question (1) (f))

5. Mantissa and exponent

1
Antonio Johnson “Straight A’s”
CAPE COMPUTER SCIENCE UNIT 1 CLASS (April 2018)
Name:
Date:

Mantissa and Exponent is a format that allows us to store large numbers as well as fractions. It is
very similar to the scientific notation of numbers Eg. 10.67x103 where 10.67 would be the Mantissa,
3 would be the exponent and 10 would be the base.

To convert a number to Mantissa and exponent (taken from Invitations to Computer Science):

a) Convert the number to binary


b) Next normalize until the first significant digit is to the right of the decimal point (see
board)
c) The number of times you moved the decimal point to get step (b) in decimal would be
your exponent.
d) Write the sign of the mantissa, the mantissa, sign of the exponent, exponent (may vary
depending on what the question asks)

Eg. Using 8-bit mantissa, and 8-bit exponent calculate 123 in binary floating point.

12310= 011110112 (mantissa) 01111011 00000111

12310=0.1111011x107 M E

710=00000111 (exponent)

Try This: Using 1-bit sign, 3-bit exponent, and 5-bit mantissa to calculate the following number
001101011. (May/June 2015 Question (1) (f))

Try This: Using 1-bit sign, 3-bit, and 5-bit exponent, calculate 001110110(May/June 2014 Question
(1) (f))

6. Sign-Magnitude

Sign Magnitude is way of representing a number with the first bit being the sign and the remaining
bits being the number.

7. Floating Point Decimal

(see board)

Try This: Convert 13.25 to Binary. (May/June 2016 (1)(e))

Modulej 1 Objective 2

8. Logic Gates

A B A^B AvB ~A ~(A^B)


0 0

2
Antonio Johnson “Straight A’s”
CAPE COMPUTER SCIENCE UNIT 1 CLASS (April 2018)
Name:
Date:

A B A⊕B (A⊕B)’
1
1
1
1

May/June 2013 Question (1)(d)

May/June 2011 Question (1)

9. Multiplexer

A multiplexer is a device that selects one of multiple input signals and forwards the selected input to
the output line.

Input Lines = 2n

Selector Lines= n

Output Lines= 1

3
Antonio Johnson “Straight A’s”
CAPE COMPUTER SCIENCE UNIT 1 CLASS (April 2018)
Name:
Date:

Try This: Draw a clearly labelled block diagram of a 2:1 multiplexer (May June 2014)

10. Demultiplexer

A demultiplexer is a device that takes a single input line and routes it to one of the several digital
outputs. A demultiplexer has n selector lines, 2n output lines and 1 output lines.

Try This: Draw a clearly labelled block diagram of 1 to 8 DEMUX

11. Encoder

An encoder is a device

12. Decoder

A decoder converts a code into a set of signals. A decoder has ‘n’ input lines and 2n output lines.

Try This: Draw a clearly labelled block diagram of a 3 to 8 Decoder (May/June 2015 (1)(c))

Module 3

13. Struct Manipulation

To Define a struct
1. struct structname {
2. int var1;
3. int var2;
4. };
To declare an instance of a struct
1. struct structname struct1, struct2;
To manipulate a struct
1. int main() {
2. struct1.var1 = 10;
3. printf("%d", struct1.var1);
4. return 0;
5. }
To Swap a struct (see board)

4
Antonio Johnson “Straight A’s”
CAPE COMPUTER SCIENCE UNIT 1 CLASS (April 2018)
Name:
Date:

Try This: (May/June 2016 Question 6)

Try This (May June 2012 Question 6)

14. Sum of Multiples

To find the sum of multiples of a number between two boundaries, you must use the % (modulus)
operator. The mod operator gives the remainder of a number and by factor theorem, if a remainder
is 0, then it is a multiple (i.e it is divisible by that number)

E.g. (May/June 2016 Question 6)

5
Antonio Johnson “Straight A’s”
CAPE COMPUTER SCIENCE UNIT 1 CLASS (April 2018)
Name:
Date:

15. File Manipulation

To declare file

FILE *fp

To open file (mode= a-append, r-read,w-write)


1. fp = fopen(“filename.txt”, ”mode”);

Reading multiple lines in a file


1. while (!feof(fp)) {
2. fscanf(fp, ”conversion_specifier”, & varnum[i], & varstring[i]);
3. }