I am implementing the SHA-2 algorithm in Java. However, I have run into a problem. I need to append two hex values into one, but I am unable to do so. I tried appending the two as a string and using Long.parseLong(appendedString) but that causes a number format exception. Is there anyway I can do this in Java? If not is there anyway to do this in C and I’ll just implement it in C? Thanks for reading.
Here is the code:
String temp = h[0] + "" + h[1]; //Where h[0] and h[1] are two hex values stored as Long
//I also tried String temp = String.valueOf(h[0]) + String.valueOf(h[1]); but no dice
Long appended = Long.parseLong(temp); //Number format exception here
When I say append I mean something like: 0x6a09e667 + 0xbb67ae85 = 0x6a09e667bb67ae85
I’m assuming your code looks something like this:
and you want the output of
0x6a09e667bb67ae85.You can do this with some bit-shifting, such as the following: