Question

In: Computer Science

Assume that we are executing the following code on a 32-bit machine using two’s complement arithmetic...

Assume that we are executing the following code on a 32-bit machine using two’s complement arithmetic for signed integers. Which of the following will be printed when the following code is executed (circle those printed, and show work; e.g., how the values are stored):

#include <stdio.h>

int main()

{

char x = 0xF;                // x = ________

char y = -1;                 // y = ________

unsigned char z = 0xFF;      // z = 11111111       

if (x<z)

    printf("performed unsigned compare, x = %u, z = %u\n", x, z);

else

    printf("performed signed compare, x = %d, z = %d\n", x, z);

printf("y>>4 = %d\n", y>>4);    // y>>4 = __________

printf("z>>4 = %d\n", z>>4);    // z>>4 = __________

}

  1. performed unsigned compare, x = 15, z = 255
  2. performed unsigned compare, x = 15, z = -1
  3. performed signed compare, x = 15, z = -1
  4. y>>4 = -1
  5. y>>4 = 15
  6. z>>4 = -1
  7. z>>4 = 15

Hint: Recall that the %u specifier is used to display the decimal value as an “unsigned” value

Solutions

Expert Solution

#include <stdio.h>

int main()

{

//0x is used to declare hexadecimal value--

char x = 0xF;                // F in haxadecimal= 1111 in binary so,x = 1111

char y = -1;                 // y = -1

unsigned char z = 0xFF;      // z = 11111111       

if (x<z) //(1111<11111111) = True, so if statement will print

    printf("performed unsigned compare, x = %u, z = %u\n", x, z); // x= decimal value of x and z = decimal value of z

// 1111 = = 8+4+2+1 = 15

//11111111 = = 128+64+32+16+8+4+2+1 = 255

else // it will not be executed

    printf("performed signed compare, x = %d, z = %d\n", x, z);

printf("y>>4 = %d\n", y>>4);    // y>>4 = -1

printf("z>>4 = %d\n", z>>4);    // z>>4= 11111111>>4

// >> means bitwise right shift

z = 0000 0000 1111 1111

z>>1 = 0000 0000 0111 1111

z>>2 = 0000 0000 0011 1111

z>>3 = 0000 0000 0001 1111

z>>4 = 0000 0000 0000 1111

1111 = 15

Hence, the output will be:-

a) performed unsigned compare, x = 15, z = 255

b) y>>4 = -1

c) z>>4 = 15


Related Solutions

1. What is the two’s complement of: 00110101 2. Carry out the following calculation using 8-bit...
1. What is the two’s complement of: 00110101 2. Carry out the following calculation using 8-bit signed arithmetic (convert to 8-bit binary sequences) and use two’s complement for the negative number, give the result as both an 8-bit binary sequence and in base 10: 127 – 74. 3. What does shifting a binary sequence to left by 3 places correspond to (from the arithmetic standpoint)
Perform the following calculation in a 6-bit two’s complement system. Show your work. Indicate at the...
Perform the following calculation in a 6-bit two’s complement system. Show your work. Indicate at the end if there will be overflow/underflow or not and why. 1810 – 1010
Design a 32 bit after using a single 4 bit using verilog code
Design a 32 bit after using a single 4 bit using verilog code
Find the decimal equivalents for the following 8-bit two’s complement numbers. a. 0010 0100 Decimal Equivalent...
Find the decimal equivalents for the following 8-bit two’s complement numbers. a. 0010 0100 Decimal Equivalent ___________ b. 1010 1001 Decimal Equivalent ___________ c. 1100 0011 Decimal Equivalent ___________ d. 0101 0101 Decimal Equivalent ___________
Design a 32 bit adder using a single 4 bit adder using verilog code
Design a 32 bit adder using a single 4 bit adder using verilog code
Solve each of the following problems by translating the values into two’s complement notation (using patterns...
Solve each of the following problems by translating the values into two’s complement notation (using patterns of 5 bits), converting any subtraction problem to an equivalent addition problem, and performing that addition. Check your work by converting your answer to base 10 notation. (Watch out for overflow.) a. 5 + 1 b. 12 – 5 c. 5 – 11 d. 12 + 5 e. 5 – 1
Binary How is 00001001 (base 2) represented in 8-bit two’s complement notation? Convert 0.3828125 to binary...
Binary How is 00001001 (base 2) represented in 8-bit two’s complement notation? Convert 0.3828125 to binary with 4 bits to the right of the binary point. How is 00110100 (base 2) represented in 8-bit one's complement.  
Convert the base-10 number to Two’s Complement. Show your work. (a) −12 (b) −32 (c) −57...
Convert the base-10 number to Two’s Complement. Show your work. (a) −12 (b) −32 (c) −57 (d) −112 (e) −24 (f) −85
Evaluate the following expressions, where two’s complement numbers, A is 11111110 and B is 00000010 and...
Evaluate the following expressions, where two’s complement numbers, A is 11111110 and B is 00000010 and indicate the results. a. A + B b. A – B c. B–A d. –B e. – (-A)
verilog code to implement 32 bit Floating Point Adder in Verilog using IEEE 754 floating point...
verilog code to implement 32 bit Floating Point Adder in Verilog using IEEE 754 floating point representation.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT