I am having a hard time trying to perform what should be a simple conversion from an integer to a byte array.
I feel this must be simple, even trivial, but cannot get it (so if anyone know the right "name" for this operation, please tell me). Also, I couldn't find a better question title, but I feel it's a bit vague (feel free to edit).
What I want:
byte[] result = MagicConverter.Convert(336);
// now result should be {0, 0, 1, 80}
The result of converting 336 should be 1, 80
because that is the decomposition in base 256, that is, 1*256 + 80 = 336.
My codebase contain a lot of bitshifting stuff to perform similar tasks, but I think I'm not quite inderstanding this bitshifting thing yet.
BitConverter.GetBytes(366);
Should do the trick.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments