Re: BitConverter.ToInt16() Trying to understand "behind the scenes"
- From: "Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT dot.state.fl.us>
- Date: Tue, 7 Jun 2005 10:48:02 -0400
Hi,
It called little endian, a byte ( 16 bits ) are stored reversed, it's been
a architecture of Intel processors since the beginning, I don;t remember
right now the reasons though.
a search for little endian got me this link in google:
http://www.cs.umass.edu/~verts/cs32/endian.html
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Lenn" <Lenn@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:6147E9CB-16D6-4085-ACA2-331460C423CB@xxxxxxxxxxxxxxxx
> This probably something stupid, or I am missing some fundemantal concept,
> but
> I can't figure this one out.
>
> Consider the following code:
>
> byte[] bd = new byte[2];
> bd[0] = 0x00;
> bd[1] = 0x01;
>
> System.Int16 a;
> a = System.BitConverter.ToInt16(bd, 0);
> MessageBox.Show(a.ToString());
>
> BitConverter.ToInt16 returns 16 bit signed integer at specified position
> in
> a byte array.
> So, one would think hex value 0x0001 is 1 in decimal, no the following
> code
> produces 256 which is 0x0010. Now switch around values in byte array:
>
> byte[] bd = new byte[2];
> bd[0] = 0x01;
> bd[1] = 0x00;
>
> System.Int16 a;
> a = System.BitConverter.ToInt16(bd, 0);
> MessageBox.Show(a.ToString());
>
> The code above does produce 1. But hex 0x0100 is 256.
>
> Can someone explain this?
.
- Follow-Ups:
- Re: BitConverter.ToInt16() Trying to understand "behind the scenes"
- From: James Curran
- Re: BitConverter.ToInt16() Trying to understand "behind the scenes"
- References:
- Prev by Date: Re: Test if host is online
- Next by Date: Re: BitConverter.ToInt16() Trying to understand "behind the scenes"
- Previous by thread: BitConverter.ToInt16() Trying to understand "behind the scenes"
- Next by thread: Re: BitConverter.ToInt16() Trying to understand "behind the scenes"
- Index(es):
Relevant Pages
|