I have a Java BigInteger containing two bytes (ex: 1000000100110111). I would like to shift only a single nibble, the right-most nibble in the left byte (in bold below) to the left by one bit:
1000 0001 00110111
Making the result after the shift:
1000 0010 00110111
Any thoughts on the best way to go about doing this?
Thanks,
Chris
If you only want to shift a single bit, you should rather clear the old and set the new:
If you want to shift those next to four most left bits, you could bitmap them out, shift them, and then or them back:
Or for clarity:
If you don’t want 1100 1111 to become 1101 1110 (notice the spill), you can apply the bitmap again on the shifted, before the or.