RE: at2 swap_nibbles

"Oded Arbel" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
 
 



-----Original Message-----
From: Andreas Fink [mailto:[email protected]]
Sent: Monday, November 25, 2002 7:44 PM
To: Oded Arbel
Cc: [email protected]
Subject: Re: at2 swap_nibbles



It matters because of this: 

return ( ( byte & 15 ) * 10 ) + ( byte >> 4 ); 

The >> operator is allowed to sign-extend its operand, so that -16 
(0xf0h) becomes -1 (0xffh). It won't do this if chars are unsigned, 
in which case 0xf0h just becomes 0x0fh. 



correct. the other option would be to OR away all the unneeded bits like this: 
the function is in any case wrong. 

Assume you got 0xF3 and you are supposed to get 0x0F 

byte & 15 = 0x03 
(byte & 15) * 10 = decimal 30 = 0x14 
( ( ( byte & 15 ) * 10 ) + ( byte >> 4 ) = 0x14 + 0x0F = 0x33. 

Is it anywhere used at all? 


 
Yes. will somebody just shoot me where I stand ? will save me lots of trouble ;-)
I shoud have said
return ( ( byte &  0x0F )  << 4 )  |  (  ( byte  & 0xF0 ) >> 4 ); 
I'll fix ?
 
--
Oded Arbel
m-Wise mobile solutions
[email protected]
 
+972-9-9581711 (116)
+972-67-340014
 
::..
A journey of a thousand sites begins with a double click.
 -- Net Philosophies
 

______________________________________________________
 Scanned and protected by Inflex and McAfee AntiVirus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.