Re: at2 swap_nibbles

Andreas Fink <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
>> 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?


Andreas Fink
Fink Consulting GmbH

---------------------------------------------------------------
Tel: +41-61-6666332 Fax: +41-61-6666331  Mobile: +41-79-2457333
Address: Clarastrasse 3, 4058 Basel, Switzerland
E-Mail:  [email protected]
Homepage: http://www.finkconsulting.com
---------------------------------------------------------------
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.