I have two problems in general. Please reply asap.
1. I have 128 bit string value.. something like "100000000000000000001111111000000000000000011111100000000000000000000" upto 128 bit long, and I need to do left shift onto it. How would I do that? The problem is java does not take any value which is this much long and if I try to divide this string and then do left shift, answer will be different.
2. Again, if I have a number like 10010, and if I apply left shift on it , it should give me answer like 00101 and not 100100. How would I do this ?
If. as the title states, the data is a "string" value, then isn't shifting just creating a new string (with the left side chopped off and a new character appended to the right)? This problem is about processing the string, and not really about any shifting of bits.
You are right, Bigdecimal does help me. For the second question, how would i perform rotate operation on BigInteger value ?
I am suppose to do binary operation. I am having i/p as hex which i am converting in binary string. then i need to do other operations as mentioned above. I need to do bit rotate operation in Biginteger. Do you have anny idea?
Could this not be achieved by using some of the other bit-related methods from BigInteger, for instance read the most left bit, then shift, then set the most right bit to the one read before the shift?
Joined: Nov 09, 2011
I also thought of doing the same, but I am not sure how to do such a code.
Also, you mentioned you need to do other operations after you rotate the bits. Could you not just take the original string, then remove the most left character, append it to the right, and then convert it to BigDecimal or BigInteger to do the other calculations?