Cast de Int32 a byte[]

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
int t = 14;
byte[] ba = BitConverter.GetBytes(t);
int i = BitConverter.ToInt32(ba, 0);
 
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.
 
Back
Top