This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Convert to binary and take the 8 least significant bits as signed:
989 decimal = 1111011101 binary. the least significant 8 bits are 11011101 which is -35 decimal.
Upon experimentation, and with absolutely no proof whatsoever, in the cases here, you can continually subtract 256 until you are in the range of -128 to 127. That may be easier if it is correct. [ May 10, 2005: Message edited by: Timmy Marks ]
I found a round about way for this.If anybody has an easier way please reply
for byte b=(byte)256; sop(b); we get b=0;
So if x is the number its equivalent byte value is got by the formula
"Decide what you want, decide what you are willing to exchange for it. Establish your priorities and go to work."
Joined: May 06, 2005
I continual subtract 128 . but it sometime going to wrong output. That is I assure positive number means it will give negative number…
Joined: Dec 01, 2003
Are you looking for the easiest way in your head/on paper or the easiest way for a computer? I would assert that the computer can do it more easily with the %256 method, but that most people can do it for most smaller numbers with the -256 method. For extremely large numbers, I would recommend converting the lowest 8 bits to binary as the quickest method.