I need to take a numeric input which is greater than 64 bits, ensure only the remaining 83 bits (if input is greater than 83 bit) are discarded and convert it into a hex string.
I have found I can use BigInteger (System.Numerics.BigInteger) to accept the numeric input from the user but I am unsure how to proceed with this. I have outlined my approach below:
BigInteger myBigInteger = BigInteger.Parse("123456789012345678912345");
byte[] myByte = myBigInteger.ToByteArray();
if (myByte.Length < 11) // if input is less than 80 bits
{
// Convert Endianness to Big Endian
// Convert myBigInteger to hex and output
}
// Drop the elements greater than 11
// Convert element 10 to int and & it with 0x7F
// Replace the element in the array with the masked value
// Reverse array to obtain Big Endian
// Convert array into a hex string and output
I am not sure what I have in mind is the correct approach to solve this problem. Any advice would be appreciated.
Thanks.