Convert integer to byte array

heltonbiker

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.

driis
BitConverter.GetBytes(366); 

Should do the trick.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android: Convert byte array to integer array

From Dev

Method to convert byte array to integer without looping?

From Dev

How to convert byte array into integer value

From Dev

fast way to convert integer array to byte array (11 bit)

From Dev

Convert BYTE* to Array<byte>^

From Dev

Convert variable-sized byte array to a integer/long

From Dev

How to convert an integer value into 'n' digit ascii byte array in java

From Dev

How can I convert a byte array to an integer more elegantly in Python

From Dev

How to convert an integer value into 'n' digit ascii byte array in java

From Dev

How can I convert an integer to a hex byte stored in a char array?

From Dev

Java integer convert to only 2 byte array missing extra 00

From Dev

Convert integer to byte but do not overflow

From Dev

PHP convert byte string into integer

From Dev

Converting integer array to byte array

From Dev

convert integer to byte if the integer is less than 16

From Dev

Convert Stream to Byte Array

From Dev

Convert byte array to object

From Dev

Convert byte array to Image

From Dev

Convert byte array to pdf

From Dev

Convert byte array to picture

From Dev

Convert Byte array to an Icon

From Dev

Convert datatable to byte array

From Dev

Convert byte Array into DataTable

From Dev

Convert byte array to pdf

From Dev

Convert XDocument to byte array (and byte array to XDocument)

From Dev

How can I convert a 64bit integer to a big-endian byte array in C++

From Dev

How can I convert a 64bit integer to a big-endian byte array in C++

From Dev

Most stable way to convert a 32bit unsigned integer to big endian byte array?

From Dev

Convert JsonObject array to integer

Related Related

HotTag

Archive