Re: From ushot to byte[]



Hello

I am not sure about the better way, but your sample is not the best one,
because it's totaly wrong.
More corectly will be:

m_bMsg[0] = (byte)(sTrackNumber & 0xFF); // low byte
m_bMsg[1] = (byte)((sTrackNumber >> 8) & 0xFF); // hi byte

Of course we can swap bytes order. But you need not to shift anything by 16
bits.


--
With best regards,
Andrew

http://www.codeproject.com/script/profile/whos_who.asp?id=1181072


"Salvatore Di Fazio" <salvatore.difazio@xxxxxxxxx> wrote in message
news:1126095263.477498.289000@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hi guys,
> I've a ushort variable and I need to copy it in an array of byte.
> I wrote:
>
> m_bMsg[0] = (byte) (p_sTrackNumber & 0xff00 >> 8);
> m_bMsg[1] = (byte) (p_sTrackNumber & 0x00ff >> 16);
>
> but I would like to know if exist a better way by a C# class.
> Tnx
>


.



Relevant Pages

  • 2 dimension arrays
    ... As he goes thru the system, he will be updating and editing the array. ... TIA. ... Andrew. ... Prev by Date: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Diferent numbers
    ... > Andrew @ Rockface wrote: ... >> new number against the elements in the array. ... Prev by Date: ...
    (alt.php)
  • Re: SUMIF based on two conditions
    ... This is an example of an "array" formula. ... hold down the CTRL and SHIFT keys as you press the ENTER key. ... Andrew ... Prev by Date: ...
    (microsoft.public.excel.worksheet.functions)
  • Re: From ushot to byte[]
    ... search for System.encoding.ascii.* for ushort variables. ... > I've a ushort variable and I need to copy it in an array of byte. ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Keeping an Array in Memory
    ... Andrew wrote: ... > reloaded each time a .php script is run. ... I could load the array from a file ... > stay in memory until the server is shutdown ...
    (comp.lang.php)