<a href="http://www.catb.org/~esr/faqs/smart-questions.html" target="_blank" rel="nofollow">How To Ask Smart Questions</a>
posted 14 years ago
Originally posted by West Richard: Hi everyone,
In that case let's say if i have the number -8 and +10. How do i convert them to signed bytes respectively?
[ October 14, 2005: Message edited by: West Richard ]
Even better than the above, you can just do this:
This works because these numbers are in the range of valid values for bytes. Also, they are already *signed*.
Perhaps you meant "unsigned" instead. If so, assigning these values to variables is the same, assuming you are actually interested in the bit pattern of the value -8, for instance. Once you do the assignment, you just treat the variable as if its unsigned. You can do any bit-wise operations you wish, as long as you cast the result back to a byte. (The result of &, |, ^, >>, and << is promoted to an int for some reason.)
I hope this answers your question. If not, perhaps you can illustrate what you are trying to do with some more specific code.