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

Tech-Archive recommends: Fix windows errors by optimizing your registry



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: 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: Converting to big -endian
    ... array an looped backwards then use the bitocnverter with the proper index. ... r u the same Kevin Spencer from takempis.com? ... Convert.ToUint16 only does extension and signed/unsigned conversion. ... a little endian machine ...
    (microsoft.public.dotnet.framework)
  • Re: Byte
    ... nur in Java nicht). ... da kann ich doch auch gleich die Intziffer in ein Byte Array umwandeln, ... Jede Intziffer ist äquivalent zu ihrer Hexziffer 0-9, ... - binär big Endian, little Endian, BCD, ... ...
    (de.comp.lang.java)