I assume you are writing a "binary" data type of some form: if so, the simplest solution is to handle it in a loop and do the math yourself:
byte[] inp = new byte[32] { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1 };
byte b = 1;
for (int i = 31; i >= 0; i--)
{
b += inp[i];
inp[i] = (byte)(b % 2);
b = (byte)(b / 2);
}
Quote:
Sorry the dots were supposed to show total width as up to 8*32=256 bits. I didn't explain myself well enough.
Ah... details are important!
That makes it simpler:
byte[] inp = new byte[32] { ... };
int carry = 1;
for (int i = 31; i >= 0; i--)
{
carry += inp[i];
inp[i] = (byte)carry;
carry >>= 8;
}