Question: A short value is stored in 16 bits. Write a program that prompts the user to enter a short integer and displays the 16 bits
A short value is stored in 16 bits. Write a program that prompts the user to enter a short integer and displays the 16 bits for the integer. Here are sample runs:


Enter an integer: 5 JEnter The bits are 0000000000000101 Enter an integer: -5 J Enter The bits are 1111111111111011 Example (using bytes in the exumple) Description Operator Name 10101110 & 10010010 yields 10000010 Bitwise AND The AND of two corresponding bits yields a l if both bits are 1. 10101110 | 10010010 yields 10111110 The OR of two corresponding bits yields a 1 if either bit is 1. Bitwise inclusive OR 10101110 A 10010010 yields 00111100 The XOR of two corresponding bits yields a 1 only if two bits are Bitwise exclusive OR different. One's -10101110 yields 01010001 The operator toggles cach bit from O to I and from 1 to 0. complement 10101110 < < 2 yields The operator shifts bits in the first operand left by the number of bits specified in the second operand, filling with Os on the right. < < Left shift 10111000 10101110 >> 2 yields Right shift with sign extension The operator shifts bit in the first operand right by the number of bits specified in the second operand, 11101011 00101110 >> 2 yields 00001011 filling with the highest (sign) bit on the left. Unsigned right 10101110 >>> 2 yields The operator shifts bit in the first operand right by the number of bits specified in the second operand, filling with Os on the left. >>> shift with zero 00101011 extension 00101110 >>> 2 yields 00001011
Step by Step Solution
3.39 Rating (158 Votes )
There are 3 Steps involved in it
Output Enter an integer 5 The 16 bits are 000000000101 Computer archi... View full answer
Get step-by-step solutions from verified subject matter experts
