Re: BitConverter.ToInt16() Trying to understand "behind the scenes"

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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?


.



Relevant Pages

  • Re: g77 and DVF works fine but ifc causes a run-time error! Any ideas?
    ... Just because an array of size 1 has only one element, ... The standard does not allow you to pass a named scalar ... automatic code writing software isn't likely to special-case ... There are also a bunch of reasons that are a bit on the strage side ...
    (comp.lang.fortran)
  • Re: ReDimed Array size
    ... It also leads to possibilities of out-of-memory problems owing to memory fragmentation. ... to automatically redim the array instead of raising the error should not be an overhead. ... that has many reasons for being one or the other--there are historical reasons of compatibility as well as applications where one or the other makes common sense. ... I think it's a remain from the old days and also an inheritance from low level languages, but it's not good for a high level language. ...
    (microsoft.public.vb.general.discussion)
  • Re: C# storing images within an array
    ... Please figure out how to use the "other" Google user interface, the one that does not cause you to break conversation threads when you reply. ... I am now looking to create an array to store images. ... If you have an array of bytes, all you can do is move the bytes around, until you use them to create a new Image object. ... is in memory already, from where else _would_ the MemoryStream "take the image"? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: FloatToStr Reals and whole numbers on XP
    ... - Bit order when writing a hexadecimal constant. ... Endian when writing a multibye quantity as an array of bytes. ...
    (comp.lang.pascal.delphi.misc)
  • Re: C# storing images within an array
    ... don't know why Google even offers the broken version, ... I am now looking to create an array to store images. ... until you use them to create a new Image object. ... What do you mean by "take the image from memory"? ...
    (microsoft.public.dotnet.languages.csharp)