开发者

objC bitwise add

开发者 https://www.devze.com 2023-02-27 17:44 出处:网络
Where val = 3325 val &= 65535; [rtnData appendData:[[NSString stringWithFormat:@\"%x\", val] dataUsingEncoding:NSUTF8StringEncoding]];

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消