Discussion:
[Gambas-user] big-endian / little-endian conversion
Ru Vuott
2013-08-03 16:14:29 UTC
Permalink
Hello,

I was trying a big-endian / little-endian conversion.

In web I found this C function:

((word>>8) & 0x00FF) | ((word<<8) & 0xFF00)

word is a " 16bit " value.


Well,

I translated that function in Gambas:

Print Hex((Shr(&2301, 8) And &00FF) Or (Shl(&2301, 8) And &FF00))

I was waiting for this value: 01 23

but I do not understand why I obtain this results: 23 01 23


Where do I make the mistake ?

Thanks

vuott
Jussi Lahtinen
2013-08-03 17:23:15 UTC
Permalink
Dim word As Short = &2301

Print Hex((Shr(word, 8) And &00FF) Or (Shl(word, 8) And &FF00))


Or:

Print Hex((Shr(CShort(&2301), 8) And &00FF) Or (Shl(CShort(&2301), 8) And
&FF00))


Jussi
Post by Ru Vuott
Hello,
I was trying a big-endian / little-endian conversion.
((word>>8) & 0x00FF) | ((word<<8) & 0xFF00)
word is a " 16bit " value.
Well,
Print Hex((Shr(&2301, 8) And &00FF) Or (Shl(&2301, 8) And &FF00))
I was waiting for this value: 01 23
but I do not understand why I obtain this results: 23 01 23
Where do I make the mistake ?
Thanks
vuott
------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent
caught up. So what steps can you take to put your SQL databases under
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
Gambas-user mailing list
https://lists.sourceforge.net/lists/listinfo/gambas-user
Ru Vuott
2013-08-03 18:12:19 UTC
Permalink
Hello Jussi,

thank you for your suggestion.


Bye
Vuott





--------------------------------------------
Sab 3/8/13, Jussi Lahtinen <***@gmail.com> ha scritto:

Oggetto: Re: [Gambas-user] big-endian / little-endian conversion
A: "mailing list for gambas users" <gambas-***@lists.sourceforge.net>
Cc: "Benoit" <***@users.sourceforge.net>
Data: Sabato 3 agosto 2013, 19:23

Dim word As Short = &2301

Print Hex((Shr(word, 8) And &00FF) Or (Shl(word, 8) And
&FF00))


Or:

Print Hex((Shr(CShort(&2301), 8) And &00FF) Or
(Shl(CShort(&2301), 8) And
&FF00))


Jussi
Post by Ru Vuott
Hello,
I was trying a big-endian / little-endian conversion.
    ((word>>8) & 0x00FF) |
((word<<8) & 0xFF00)
Post by Ru Vuott
  word is a  " 16bit "  value.
Well,
     Print Hex((Shr(&2301, 8)
And &00FF) Or (Shl(&2301, 8) And &FF00))
Post by Ru Vuott
I was waiting for this value:   01 23
but I do not understand why I obtain this
results:  23 01 23
Post by Ru Vuott
Where do I make the mistake ?
Thanks
vuott
------------------------------------------------------------------------------
Post by Ru Vuott
Get your SQL database under version control now!
Version control is standard for application code, but
databases havent
Post by Ru Vuott
caught up. So what steps can you take to put your SQL
databases under
Post by Ru Vuott
version control? Why should you start doing it? Read
more to find out.
Post by Ru Vuott
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
Gambas-user mailing list
https://lists.sourceforge.net/lists/listinfo/gambas-user
------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but
databases havent
caught up. So what steps can you take to put your SQL
databases under
version control? Why should you start doing it? Read more to
find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
Gambas-user mailing list
Gambas-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Loading...