PC Review


Reply
Thread Tools Rate Thread

Cast de Int32 a byte[]

 
 
=?Utf-8?B?QmxhY2tfYW5nZWw=?=
Guest
Posts: n/a
 
      2nd Mar 2005
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.



 
Reply With Quote
 
 
 
 
William Stacey [MVP]
Guest
Posts: n/a
 
      2nd Mar 2005
int t = 14;
byte[] ba = BitConverter.GetBytes(t);
int i = BitConverter.ToInt32(ba, 0);

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

"Black_angel" <(E-Mail Removed)> wrote in message
news:8EA576BE-2832-4C60-811A-(E-Mail Removed)...
> 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.
>
>
>


 
Reply With Quote
 
=?Utf-8?B?QmxhY2tfYW5nZWw=?=
Guest
Posts: n/a
 
      2nd Mar 2005
Thank you very much!



"William Stacey [MVP]" wrote:

> int t = 14;
> byte[] ba = BitConverter.GetBytes(t);
> int i = BitConverter.ToInt32(ba, 0);
>
> --
> William Stacey, MVP
> http://mvp.support.microsoft.com
>
> "Black_angel" <(E-Mail Removed)> wrote in message
> news:8EA576BE-2832-4C60-811A-(E-Mail Removed)...
> > 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.
> >
> >
> >

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to cast object of type 'System.Int32' to type 'System.Byte[ ChaseW Microsoft Outlook BCM 1 22nd Aug 2009 10:03 AM
System.int32[*] to System.int32[] explicit cast problems northerntechie Microsoft VB .NET 1 14th Sep 2007 06:22 PM
Invalid cast from 'Int32' to 'DateTime' =?Utf-8?B?S2luZ0xlYXI=?= Microsoft ASP .NET 0 25th Aug 2006 04:24 PM
Warning 1684 CA2214 : Microsoft.Usage : 'RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)' contains a call chain that results in a call to a virtual method defined by the class. Review the following call stack for unintended consequences: steve bull Microsoft C# .NET 4 7th Jul 2005 05:54 PM
Invalid cast from System.Int32 to System.Byte[]. =?Utf-8?B?SGlmbmkgU2hhaHphcmQ=?= Microsoft ASP .NET 1 15th Feb 2005 03:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:34 AM.