Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MrStevieP

macrumors newbie
Feb 27, 2008
22
0
Can you give any more information? Have you reassigned the item after using the AND?

A code snippet would be handy o diagnose this problem
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
When I read the post earlier I was on my phone and didn't want to try to type everything out there.

Essentially the issue appeared to be sign extension. The highest bit of the uint8 was a 1, so the sign got extended to the higher order bytes when cast to a 32-bit int. The result would have varied in other test cases, as the 0 sign bit extension wold have "looked different".

Essentially, however, you should have gotten the same numerical result (though signed, not unsigned) no matter what, as in 2s complement sign extension will not modify the value. You had wanted your uint8 to be unsigned, but turning it into an int and not an unsigned int caused the issues you saw.

It seems like you figured it out already, but wanted to toss this out there for others that might read the thread.

In the future when you resolve something it might be nicer to leave the post and add the solution in the edit or a new post for others to learn from. I don't think it was a silly question and I'm sure others will run into something similar at some point.

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.