(new post to reduce individual post size stress on MySql database)
method to convert signed char to signed dec:
Code: Select all
f(x)={
return ((x&0x80)?-1:1)*(x^((x&0x80)?0x7f:0));
// the following is incorrect to append: +((x&0x80)>>7)
}
remember:
Code: Select all
& is bitwise and
^ is bitwise xor
* is multiplication
foo?truthcase:falsecase is a boolean switch
>> is shift right
+ is addition
0xfoo is hexidecimal
// is a comment
<= is a less than or equal to inequality test that returns in most cases 1 for truth, 0 for false depending on the programming language
remember basica, gwbasic, and quick basic use -1 for true and 0 for false.
all systems test any value other than zero as true.
i feel the comment in my method to convert signed char to signed dec code explains your confusion, Laserbeak.
the only reason negative goes -1 to -128 while positive goes 1 to 127 is that zero is "00000000"
zero is "00000000"
positive uses "00000001" thru "01111111" as 1 thru 127
negative uses "10000000" thru "11111111" as -128 thru -1