Multiplying negatives using bitwise minipulation

Pages: 12
alright im going to get back to this one tomorrow, im still getting an error. but just incase here is what i have thus far. Thank you for all your help by the way.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
unsigned float_twice(unsigned uf) {
  if((uf << 1) == 0)
        return uf;
  else if((uf & 0x80000000) != 0){
        uf = uf^0x80000000;
        uf = uf << 1;
        uf = uf^0x80000000;
        return uf;
  }
  else
        return uf<<1;


}
(k=0x80000000)
One more thing: by doing y=x&k you can save the sign of the number. x|~k removes it, and x|y restores it.
Topic archived. No new replies allowed.
Pages: 12