0% found this document useful (0 votes)
38 views

Computer Science 1 - Assignment 1 Answers

Uploaded by

Knzy Elmasry
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)
38 views

Computer Science 1 - Assignment 1 Answers

Uploaded by

Knzy Elmasry
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/ 10

Part B:

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

Number Binary remainders Octal remainders Hexadecimal remainders


system

58/2 = 29 0*2 = 0 58/8 = 7.25 0.25*8 = 2 58/16 = 3.625 0.625*16 = 10 = A

29/2 = 14.5 0.5* 2 = 1 7/8 = 0.875 0.875*8 = 7 3/16 = 0.1875 0.1875*16 = 3

14/2 = 7 0

7/2 = 3.5 1

3/2 = 1.5 1

1/2 = 0.5 1

Final Value 111010 72 3A

Remark: remainders are just the numbers after the decimal value multiplied by the base, which
eventually make up our number.

b) 62

Number Binary remainders Octal remainders Hexadecimal remainders


system

62/2 = 31 0 62/8 = 7.75 6 62/16 = 3.875 14 = E

31/2 = 15.5 1 7/8 7 3/16 3

15/2 = 7.5 1

7/2 = 3.5 1

3/2 = 1.5 1

1/2 1

Final Value 111110 76 3E

c) 333
Number Binary remainders Octal remainders Hexadecimal remainders
system

333/2 = 166.5 1 333/8 = 41.625 5 333/16 = 20.8125 13 = D

166/2 = 83 0 41/8 = 5.125 1 20/16 = 1.25 4

83/2 = 41.5 1 5/8 5 1/16 1

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

Final Value 101001101 515 14D

d) 3333
Number Binary remainders Octal remainders Hexadecimal remainders
system

3333/2 = 1666.5 1 3333/8 = 416.625 5 3333/16 = 208.3125 5

1666/2 = 833 0 208/16 = 13 0

833/2 = 416.5 1 416/8 = 52 0 13/16 D

416/2 = 208 0 52/8 = 6.5 4

208/2 = 104 0 6/8 6

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

Final 110100000101 6405 D05


Value

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

1000001 6 0 (65/8 = 8.125), (.125*8) = 1 (65/16 = 4.0625), (.0625*16)


2 + 2 = 65 (8/8 = 1), (0*8) = 0 =1
(1/8) = 1 (4/16) = 4

Final value 65 101 41

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

Final value 122381 357015 1DE0D


Q3 add the two numbers then
subtract them using: standard subtraction, one’s complement & two’s
complement

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:

Number Binary remainders

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

4 - Perform subtraction using 1’s complement:


011 = 100 (1’s complement form)
110
100 +
= 1010

5 - Perform subtraction using 1’s complement:


011 = 100 + 1 = 101 (2’s complement form)
110
101 +
= 1011 = 011 (ignore carry)
b) 18, 6
1 - Convert to binary:

Number Binary remainders

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

4 - Perform subtraction using 1’s complement:


00110 = 11001 (1’s complement form)
10010
11001 +
= 101011 (ignore carry)
1+
= 1100

5 - Perform subtraction using 1’s complement:


00110= 11001 + 1 = 11010 (2’s complement form)
10010
11010 +
= 101100 = 1100 (ignore carry)
c) 30, 21
1 - Convert to binary:

Number Binary remainders

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

4 - Perform subtraction using 1’s complement:


10101 = 01010 (1’s complement form)
11110
01010 +
= 101000 (ignore carry)
1+
= 01001

5 - Perform subtraction using 1’s complement:


10101 = 01010 + 1 = 01011 (2’s complement form)
11110
01011 +
= 101001 = 1001 (ignore carry)

d) 28, 50
1 - Convert to binary:

Number Binary remainders

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

4 - Perform subtraction using 1’s complement:


011100 = 100011 (1’s complement form)
110010
100011 +
= 1010101 (ignore carry)
1+
= 010110

5 - Perform subtraction using 1’s complement:


011100 = 100011+ 1 = 100100 (2’s complement form)
110010
100100 +
= 1010110= 010110 (ignore carry)

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

You might also like