Cast de Int32 a byte[]

G

Guest

Hello everybody,

I want to cast an integer of 32 bits in a byte[] id.
How can I break the Int32 id up to set it in the 4 first positions of the
array of byte?
and then, How can I get the full Int32 id of the array of bytes [] ?

In MSDN appears a parse for Int to byte, but not for byte[], and if the
integer of 32 bits has a very long number can take 4bytes up (32bits/8=
4bytes).
Regards.
 
W

William Stacey [MVP]

int t = 14;
byte[] ba = BitConverter.GetBytes(t);
int i = BitConverter.ToInt32(ba, 0);
 
G

Guest

Thank you very much!



William Stacey said:
int t = 14;
byte[] ba = BitConverter.GetBytes(t);
int i = BitConverter.ToInt32(ba, 0);

--
William Stacey, MVP
http://mvp.support.microsoft.com

Black_angel said:
Hello everybody,

I want to cast an integer of 32 bits in a byte[] id.
How can I break the Int32 id up to set it in the 4 first positions of the
array of byte?
and then, How can I get the full Int32 id of the array of bytes [] ?

In MSDN appears a parse for Int to byte, but not for byte[], and if the
integer of 32 bits has a very long number can take 4bytes up (32bits/8=
4bytes).
Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top