Lab 2 - Answers
Lab 2 - Answers
Exercise 1 – Convert the following decimal numbers into binary: 6, 19, 47.
Exercise 2 – Try to work out some systematic method of converting a decimal number to a
binary string without using a software program to do it for you.
Exercise 3 – Try the following commands in MATLAB and see if you can explain the output.
1. uint8(16.5) = 17 – the unsigned integer code rounds decimal number by adding one
when the digit after the decimal point is 5 or more.
2. uint8(16.2) = 16 – the unsigned integer code rounds the decimal number by just
removing the decimal part.
3. uint8(-47) = 0 – 8 bits only allow us to work with numbers from 0 to 255.
4. uint8(436) = 255 – 8 bits only allow us to work with numbers from 0 to 255.
5. uint16(436) = 436 – 16 bits allow us to work from numbers from -32768 to 32767.
6. uint16(1000000) = 65535 – 16 bits allow us to work from numbers from -32768 to
32767.
7. uint32(1000000) = 1000000 – 32 bits allow us to work from numbers from -
2147483648 to 2147483647.
Exercise 4 – Try to predict what the outcomes of the following commands in MATLAB will
be, then check your predictions using MATLAB.
my_name =
'Edi'
>> my_name(1)
ans =
'E'
>> my_name(2)
ans =
'd'
>> my_name(100)
Index exceeds the number of array elements (3).
>> double(my_name)
ans =
69 100 105
>> 2*my_name
ans =
ans =
'HELLO'