Computer Science 1 - Assignment 1 Answers
Computer Science 1 - Assignment 1 Answers
Q1: Convert the following decimal numbers into their: Binary, Octal and Hexadecimal
equivalents. Use the repetitive division method and show all your steps:
a) 58
14/2 = 7 0
7/2 = 3.5 1
3/2 = 1.5 1
1/2 = 0.5 1
Remark: remainders are just the numbers after the decimal value multiplied by the base, which
eventually make up our number.
b) 62
15/2 = 7.5 1
7/2 = 3.5 1
3/2 = 1.5 1
1/2 1
c) 333
Number Binary remainders Octal remainders Hexadecimal remainders
system
41/2 = 20.5 1
20/2 = 10 0
10/2 = 5 0
5/2 = 2.5 1
2/2 = 1 0
1/2 1
d) 3333
Number Binary remainders Octal remainders Hexadecimal remainders
system
104/2 = 52 0
52/2 = 26 0
26/2 = 13 0
13/2 = 6.5 1
6/2 = 3 0
3/2 = 1.5 1
1/2 1
Q2: Convert the following binary numbers to their: Decimal, Octal and Hexadecimal
To convert from binary to octal or decimal, you convert to decimal and then to the desired base
Binary Number (base 2) Decimal (base 10) Octal (base 8 ) Hexadecimal(base 16)
1001 3
2 +2 = 9
0 (9/8 = 1.125), (.125*8) = 1 (9/16) = 9
(1/8), = 1
Final value 9 11 9
101010 5 3
2 + 2 + 2 = 42
1 (42/8 = 5.25), (0.25*8) = 2 (42/16 = 2.625), (.625*16) =
(⅝) = 5 10 = A
(2/16) = 2
Final value 42 52 2A
11101111000001101 2
16 15
+2 +2 (122381/16 = 15297.625),
14 12
+2 + (122381/16 = 7648.8125),
11 10 9 3 2 (.625*8) = 5 (.8125*16) = 13 = D
2 + 2 + 2 + 2 + 2 (15297/8 = 1912.125), (7648/16 = 478), (0*16) = 0
0
+ 2 = 122381 (.125*8) = 1 (478/16 = 29.875), (.875*16)
(1912/8 = 239), (8*0) = 0 = 14 = E
(239/8 = 29.875), (.875*8) (29/16 = 1.8125), (.8125*16)
=7 = 13 = D
(29/8 = 3.625), (.625*8) = 5 (1/16) = 1
(3/8) = 3
Remarks:
● to add binary numbers, if we are adding a [0 + 0 = 0], [1 + 0 = 1], [1 + 1 = 0 and the next
digit carries 1], [1 + 1 + 1 = 1 and the next digit carries 1].
● For subtraction, [0 - 0 = 0], [1 - 0 = 1], in case it’s [1 - 0], we carry from the next number
and if it is also 0, you keep borrowing until you reach a 1, afterwards, whatever you
borrow it’s now a 10 (in binary numbers) which is a 2, so [10 - 1 = 1].
● For subtraction using 1’s complement: there are 3 steps
○ Convert the number to be subtracted to its 1’s complement form (basically switch
all the 1’s to 0’s and vice versa, make sure that the number of digits in both
numbers are equal, if they’re not equal, ex: 110 and 11, you add a zero, s.t. 11 =
011).
○ Perform addition.
○ If the final carry (far left digit) is 1, add one to the result. However, if the final
carry is 0, then the result obtained is -ve and in its 1’s complement form.
● For subtraction using 2’s complement: there are 3 steps
○ Convert the number to be subtracted to its 2’s complement form (the same method
to obtain the 1’s complement form, then you add 1 to the result).
○ Perform addition.
○ If there is a final carry, then the result is +ve and in its true form. However, if the
final carry is not generated, the result is -ve and in its 2’s complement form.
a) 6, 3
1 - Convert to binary:
6 6/2 = 3 0
3/2 = 1.5 1
1/2 1
Final 110
Value
3 3/2 = 1.5 1
1/2 1
Final 11
Value
2 - Perform addition:
110
011 +
= 1001
3 - Perform subtraction:
110
011 -
= 11
6 6/2 = 3 0
3/2 = 1.5 1
1/2 1
Final 110
Value
18 18/2 = 9 0
9/2 = 4.5 1
4/2 = 2 0
2/2 = 1 0
1/2 1
Final 10010
Value
2 - Perform addition:
10010
00110 +
= 11000
3 - Perform subtraction:
10010
00110 -
= 01100
30 30/2 = 15 0
15/2 = 7.5 1
7/2 = 3.5 1
3/2 = 1.5 1
1/2 1
Final 11110
Value
21 21/2 = 10.5 1
10/2 = 5 0
5/2 = 2.5 1
2/2 = 1 0
1/2 1
Final 10101
Value
2 - Perform addition:
11110
10101 +
= 110011
3 - Perform subtraction:
11110
10101 -
= 01001
d) 28, 50
1 - Convert to binary:
50 50/2 = 25 0
25/2 = 12.5 1
12/2 = 6 0
6/2 = 3 0
3/2 = 1.5 1
1/2 1
Final 110010
Value
28 28/2 = 14 0
14/2 = 7 0
7/2 = 3.5 1
3/2 = 1.5 1
1/2 1
Final 11100
Value
2 - Perform addition:
110010
011100 +
= 1001110
3 - Perform subtraction:
110010
011100 -
= 10110
Q4
a) How many bits are needed to represent the number 500 in the binary
system? 500 = 111110100, 9 bits
b) How many numbers can be represented in the binary system using 4 bits?
How many can be represented in the octals system using 4 positions? Deduce
the general rule for n bits in a system with base b. numbers made up of four
bits: {0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011,
1100, 1101, 1111} = 16 numbers, or we could use simple math since we have 4
bits and each one can either be 0 or 1, then the number of numbers that can be
4
represented by 4 bits = 2 = 16
c) What is the number of bits needed to represent the double of a number
represented in 5 bits in the binary system?
d) How many bits does 4 words contain? A word has 16 bits, thus, 4 words have
64 bits.
e) What is the meaning of ASCII code? ASCII = American Standard Code for
Information Interchange