Topic: Operating on binary integer numbers. Arithmetic (+, -, *, /, %), Boolean (&, |, ^, ~), and shifts (<<, >>)
Related Reading: Sections 5.2, 6.2, and class notes
Solutions to the odd-numbered problems at the end of Chapters 5 and 6 are available on the textbook's companion website.
You are allowed to submit your assignment via email, but if you choose to do so, you must bring a hardcopy of your assignment along with a completed cover sheet to the instructor at the next class. (Note: Do not email the instructor any .zip file attachments, as SLU's email may not accept these emails; i.e. the instructor may not receive your email.)
Given the following variable declarations:
short a = 0b0010101100011001; short b = 0b0101100110101011; short c = 0b1111111101110010; unsigned short j = 0x95; unsigned short k = 0xF35C; int n = 0xA39D2; int p = 0x5A48;
Compute results for the following data operations.
Assume for the following problems that x and y have been declared as follows:
short x, y;
Note: x can be any value that results in valid value for y.
x = 13 y = (x << 3) - x
x = 6 y = x + (x << 1) - (x << 4)
x = 22 y = (x >> 2) + (x >> 3)
x = 117 y = x & 0x0f
Using the diagram of the ALU from Figure 5.17 in the textbook, displayed here or downloadable here:
Indicate what the 32-bit Result output, and each of the 1-bit Zero, Negative, and Carry outputs, would be for each of the following sets of inputs: