shift left/right: Shifting means exactly that, shift all the bits in the first operand either left or right the number of time indicated in the second. The second operand should be an integer value. If it is not, then truncate it (pretend the fractional part does not exist). If a shift left would push a bit off of the 'front', it is lost and causes an overflow. Report the overflow and print the bits left over after the shift. If a shift right would push a bit off of the 'back', it is lost and causes an underflow. Report the underflow and print the bits left over after the shift. e.g. (shift 2 to the left 1 time .. in essence multiply by 2) $ ./compu "000101000010" $ OKAY 1000 (shift 2 to the left 1.5 times .. not an int) $ ./compu "000101000011" $ NINT 1000
shift left/right:
Shifting means exactly that, shift all the bits in the first operand either left or right the number of time indicated in the second. The second operand should be an integer value. If it is not, then truncate it (pretend the fractional part does not exist). If a shift left would push a bit off of the 'front', it is lost and causes an overflow. Report the overflow and print the bits left over after the shift. If a shift right would push a bit off of the 'back', it is lost and causes an underflow. Report the underflow and print the bits left over after the shift.
e.g.
(shift 2 to the left 1 time .. in essence multiply by 2)
$ ./compu "000101000010"
$ OKAY 1000
(shift 2 to the left 1.5 times .. not an int)
$ ./compu "000101000011"
$ NINT 1000
(shift 2 to the left 2 times .. in essence multiply by 4, but we can't represent 8)
$ ./compu "000101000100"
$ AOVR 0000
(shift 1.0 to the left 1 time .. in essence divide by 2)
$ ./compu "001000100010"
$ OKAY 0001
(shift 1.0 to the left 2 times.. in essence divide by 4, but we can't represent 1/4)
$ ./compu "001000100100"
$ AUDR 0000
Note! If you have more than one flag on an operation, output all that apply in the order they are listed above. Only if there are no errors and no other flags should you print "OKAY". Shift is the only operation that may result in a "NINT" flag and a "AOVR" or "AUDR" flag.
![Part 0. compu: Binary time!
Write a program named 'compu' that interprets various binary commands and prints results. Your program will take a single argument and examine the text to determine if the command is correct and if so, compute it.
**Implementation**
You will receive a single instruction from the Digitally Encoded Reduced Predicate Set of 12-bit instructions (i.e. DERPS-12) in text via argv[1]. DERPS-12 is a statically-sized instruction set. Every operator and operand is 4 bits long, and every instruction consists of an operator followed by two operands. Operands are binary values with 3 bits of magnitude and 1 bit of precision with the least significant bit on the right.
**Your operators are:**
- addition: 0000
- shift left: 0001
- shift right: 0010
- compare: 0011
- -UNDEF-: 0100 to 1111
**Your operands are:**
- 0: 0000
- 0.5: 0001
- 1: 0010
- 1.5: 0011
- 2: 0100
- 2.5: 0101
- 3: 0110
- 3.5: 0111
- 4: 1000
- 4.5: 1001
- 5: 1010
- 5.5: 1011
- 6: 1100
- 6.5: 1101
- 7: 1110
- 7.5: 1111
**Your status codes are:**
- UNDF: undefined operator (fatal error)
- BSRT: too few bits (fatal error)
- BLNG: too many bits (fatal error)
- AOVR: overflow (FLAG)
- AUDR: underflow (FLAG)
- CPEQ: compare equal (FLAG)
- CPNQ: compare not equal (FLAG)
- NINT: non-integer operand (FLAG)
- OKAY: no issues (FLAG)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1d750e43-b405-4a7c-b087-1df8763fb58e%2F431c6f43-c03a-4e35-81ae-c344ba2fb4fa%2F7lbkdtw_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









