binary (i.e 01010011). 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
Write a C
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
Trending now
This is a popular solution!
Step by step
Solved in 2 steps