objC bitwise add
Where
val = 3325
val &= 65535;
[rtnData appendData:[[NSString stringWithFormat:@"%x", val] dataUsingEncoding:NSUTF8StringEncoding]];
I am expecting开发者_Go百科 <30434644> 0CFD
but getting <636664> cfd
So either 3325 is not the correct beginning val (but I have derived it from 2 different functions) or the bitwise addition is wrong.
Thanks in advance.
&
is bitwise "and", not bitwise-addition.
And the code is wrong because you have used the wrong format. Use @"%04X"
instead of @"%x"
. (where 0 = pad with 0 if not long enough, 4 = at least 4 characters, X = upper case hexadecimal)
精彩评论