"tuvok" <52***************@t-online.de> wrote in message
news:d8*************@news.t-online.com...
"invincible" wrote hi I wanted to convert Little Endian to big endian for 2 byte value
for example
if hex value of aValue = 0102
required valu e = 0201
This can be done
bValue = ( (aValue << 8) | (aValue << 8))
But how about if value is bValue = F26B
I am getting FFF2 instead of 6BF2
Try this:
bValue = (aValue << 8) | (aValue >> 8);
Hmmm... I think that would work if you make aValue and
bValue unsigned. But if they're signed, that right shift
is going to pour-in a bunch of 1s if the msb of aValue
is a 1.
example:
#include <iostream>
int main(void)
{
register signed int Blat = 0x80000000;
Blat = Blat >> 21;
std::cout << std::hex << Blat << std::endl;
return 0;
}
Do you expect that to print 400?
No, it prints fffffc00.
BUT, if you make it unsigned:
#include <iostream>
int main(void)
{
register unsigned int Blat = 0x80000000;
Blat = Blat >> 21;
std::cout << std::hex << Blat << std::endl;
return 0;
}
then it prints 400 as expected.
--
Cheers,
Robbie Hatley
Tustin, CA, USA
email: lonewolfintj at pacbell dot net
web: home dot pacbell dot net slant earnur slant
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----