Ok, I can not get my head round this, when I try and set a single bit using an equation (from a loop counter) there are rounding errors which prevent the bits from being set correctly.
Code here.
Anyone have any ideas why it outputs this
2 to power of 3 = 7.9999999999999982
2 to power of 6 = 63.999999999999979
00000000000000000000000001000110
2 to the power of 3 = 8.0000000000000000
Thanks.
Code here.
SuperStrict Local flags : Byte For Local i : Byte = 0 To 7 If i = 2 Or i = 5 flags :+ (2 ^ (i + 1) ) ' this is one less than it should be, why???? I don't see why it is rounding down. ' as no division is taking place, just multiplication. I know I can use bit shifting but ' this is more readable (and easier :?) Print "2 to power of " + (i+1) + " = " + (2 ^ (i + 1) ) End If Next Print Bin(flags) ' this outputs correctly Print "2 to the power of 3 = " + (2 ^ 3)
Anyone have any ideas why it outputs this
2 to power of 3 = 7.9999999999999982
2 to power of 6 = 63.999999999999979
00000000000000000000000001000110
2 to the power of 3 = 8.0000000000000000
Thanks.