Why are these results different, and how can I get around it?
They aren't really different. The problem here is that IEEE Floating point aritmetic is attempting to fit an infinite series of numbers into a finite ammount of space (in this case 80 or 64 bits). Ofcourse this is impossible to do with absolute accuracy (if you can figure out otherwise you might just get a nobel prize).As for a "way around it" use integer (CPU) instructions (^ is an FPU instruction) or rethink the algorithm. In your case this would be
Print 1 Shl (7-0) b:Int = 0 Print 1 Shl (7-b)