Re: From ushot to byte[]
- From: "Andrew Kirillov" <andrew.kirillov@xxxxxxxxx>
- Date: Wed, 7 Sep 2005 15:27:21 +0300
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
>
.
- References:
- From ushot to byte[]
- From: Salvatore Di Fazio
- From ushot to byte[]
- Prev by Date: Re: NUnit Documentor
- Next by Date: Re: export dataset to excel in winform
- Previous by thread: Re: From ushot to byte[]
- Next by thread: Re: From ushot to byte[]
- Index(es):
Relevant Pages
|