logo

UTK Notes


Midterm 2

Question 1

What hexadecimal number comes after 9F? Both capital and lowercase letters are accepted if needed.

0xA0

Question 2

The ~ operation will…

flip all bits.

Question 3

Convert 0x90C to binary. Use 12 bits: 4 digits in the first blank, 4 digits in the second blank, and 4 digits in the third blank.

0b1001 0000 1100

Question 4

True or False: 0 >> 1 = 0

True

Question 5

With selection sort, we find the final position for an element with each step.

True

Question 6

Which sorting algorithm divides the array into sorted and unsorted sublists?

Selection

Question 7

Which list correctly orders the numbers in order from smallest to largest?

0x1C, 0x31, 0xAB, 0xC1

Question 8

Give the result of the following operation in binary. Use 8 bits: 4 digits in the first blank, and 4 digits in the second blank. (0b0101_1011) >> 3 =

0b0000 1011

Question 9

Convert 0b1111_1011 to hexadecimal (type two digits, i.e. use a leading zero if necessary):

0xFB

Question 10

The number system with base 16 is called…

hexadecimal

Question 11

Give the result of the following operation in binary. Use 8 bits: 4 digits in the first blank, and 4 digits in the second blank. (0b0111_1000) & (0b1001_1001) =

0b0001 1000

Question 12

Which list correctly orders the numbers in order from smallest to largest?

0b0101, 0b0110, 0b1001, 0b1010

Question 13

Give the result of the following operation in binary. Use 8 bits: 4 digits in the first blank, and 4 digits in the second blank. (0b1001_0000) | (0b0111_0000) =

0b1111 0000

Question 14

Given this array: { 16, 32, 7, 12 , 22, 13, 3, 5 }

What is the order of the array after 3 steps of bubble sort?

{ 16, 7, 12, 32, 22, 13, 3, 5 }

Question 15

Match the following Unix commands with their definition.

rm - remove

scp - secure copy

cd - change directory

ssh - secure shell

chmod - change permissions

cp - copy

ls - list contents

mkdir - create directory

Question 16

Linear search is more time efficient than binary search.

False

Question 17

I run an ls -l command inside a directory, and I see this as output:

-rw-r--r--@ 1 ccc staff 2090 Apr 7 10:36 myfile.txt

What are the group’s permissions?

read only

Question 18

Give the result of the following operation in hexadecimal. Both capital and lowercase letters are accepted if needed. 0xD7 | (1 << 3) =

0xDF

Question 19

With insertion sort, we find the final position for an element with each step.

False

Question 20

Convert 0xDAD to binary. Use 12 bits: 4 digits in the first blank, 4 digits in the second blank, and 4 digits in the third blank.

0b1101 1010 1101

Question 21

Give the result of the following operation in binary. Use 8 bits: 4 digits in the first blank, and 4 digits in the second blank. (0b0101_1000) ^ (0b0101_1010) =

0b0000 0010

Question 22

I am running the insertion sort algorithm, and currently at element 10 (the third element in the list).

This is the state of my array: {15, 20, 10, 5, 35, 25}.

What step do I take next?

10 will be placed before 15, and 15 and 20 will be shifted to the right by one index

Question 23

I run an ls -l command inside a directory, and I see this as output:

-rw-r--r--@ 1 ccc staff 2090 Apr 7 10:36 myfile.txt

How would we change the permissions for the user to have read only permissions, the group to have read and write permissions, and the world to keep the same permissions as listed above?

chmod 464 myfile.txt

Question 24

Write the chmod command that gives the user read, write, and execute permissions, but the group and the world have no permissions for myfile.txt.

chmod 700 myfile.txt

Question 25

Given this array: { 5, 2, 7, 9 ,1, 3 }

What is the order of the array after 2 steps of bubble sort?

{ 2, 5, 7, 9 ,1, 3 }

Question 26

Give the result of the following operation in hexadecimal. Both capital and lowercase letters are accepted. Give two digits for your answer. ~0x22 =

0xDD

Question 27

I run an ls -l command inside a directory, and I see this as output:

-rwxr--r-x@ 1 ccc staff 2090 Apr 7 10:36 myfile.txt*

What are the user’s permissions?

read, write, and execute

Question 28

In a worst case scenario, binary search would not have to access every element of an array in order to find the element.

True

Question 29

Give the result of the following operation in binary. Use 8 bits: 4 digits in the first blank, and 4 digits in the second blank. (0b0101_1011) << 3 =

0b1101 1000

Question 30

Give the result of the following operation in binary. Use 8 bits: 4 digits in the first blank, and 4 digits in the second blank. ~(0b1011_0110) =

0b0100 1001

Question 31

Give the result of the following operation in binary. Use 8 bits: 4 digits in the first blank, and 4 digits in the second blank. ~(0b1110_0001) =

0b0001 1110

Question 32

Binary search assumes that the array is sorted before the search algorithm begins.

True

Question 33

Academic Dishonesty and Cheating

Question 34

True or False: 1 << 0 = 1

True

Question 35

Give the result of the following operation in hexadecimal. Both capital and lowercase letters are accepted. Give two digits for your answer. 0x22 | 0xA1 =

0xA3

Question 36

Give the result of the following operation in binary. Use 8 bits: 4 digits in the first blank, and 4 digits in the second blank. (0b1111_0000) ^ (0b1001_1001) =

0b0110 1001

Question 37

Give the result of the following operation in binary. Use 8 bits: 4 digits in the first blank, and 4 digits in the second blank. (0b1101_0011) << 2 =

0b0100 1100

Question 38

If a hexadecimal number ends in zero, it must be …

even

Question 39

Give the result of the following operation in binary. Use 8 bits: 4 digits in the first blank, and 4 digits in the second blank. (0b1111_0000) & (0b1001_1001) =

0b1001 0000

Question 40

I run an ls -l command inside a directory, and I see this as output:

-rw-r--r-x@ 1 ccc staff 2090 Apr 7 10:36 myfile.txt

What are the world’s permissions?

read, execute

Question 41

Linear search assumes that the array is sorted before the algorithm begins.

False

Question 42

Give the result of the following operation in binary. Use 8 bits: 4 digits in the first blank, and 4 digits in the second blank. (0b0101_1000) | (0b0001_0001) =

0b0101 1001

Question 43

In class, we created a function called clear_bit() to remove a sensor from a smartwatch. The function took one argument, which was a SensorType index - 0 for Heart Rate, 1 for Blood Pressure, 2 for SPO2, and 3 for Speed/Cadence. mySensors is the integer that we store all the sensors connected to the smartwatch and is accessible by the function.

The function is written below with one line missing. Choose the correct statement from the list to remove the given sensor from the smartwatch, and do nothing if it’s already not connected.

1
2
3
4
5
6
7
void clear_bit( SensorType index ) {

  int mask = ( 1 << index );

  //______________

}

mySensors = mySensors & (~mask);

Question 44

In class, we created a function called set_bit() to add a sensor to a smartwatch. The function took one argument, which was a SensorType index - 0 for Heart Rate, 1 for Blood Pressure, 2 for SPO2, and 3 for Speed/Cadence. mySensors is the integer that we store all the sensors connected to the smartwatch and is accessible by the function.

The function is written below with one line missing. Choose the correct statement from the list to add the given sensor to the smartwatch, and do nothing if it’s already connected.

1
2
3
4
5
6
7
void set_bit( SensorType index ) {

  int mask = ( 1 << index );

  //______________

}

mySensors = mySensors | mask;

Question 45

Convert 127 (decimal) to binary. Use 8 bits: 4 digits in the first blank, and 4 digits in the second blank.

0b0111 1111

Question 46

Convert 0x23 to decimal.

35

Question 47

What is the largest number (in decimal) that you can hold with 4 binary digits?

15

Question 48

Give the result of the following operation in binary. Use 8 bits: 4 digits in the first blank, and 4 digits in the second blank. (0b1101_0011) >> 2 =

0b0011 0100

Question 49

Convert 0x51 to binary. Use 8 bits: 4 digits in the first blank, and 4 digits in the second blank.

0b0101 0001

Question 50

The ASCII value of ‘b’ is 0x62. What is the ASCII value of ‘d’?

0x64

Question 51

Give the result of the following operation in hexadecimal. Both capital and lowercase letters are accepted. Give two digits for your answer. 0x22 & 0xA1 =

0x20

Question 52

Give the result of the following operation in hexadecimal. Both capital and lowercase letters are accepted. Give two digits for your answer. 0x22 ^ 0xA1

0x83