Prev | Current Page 143 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


Moving right to left, you can assign values to each bit that is a multiplication of 2 times the previous bit
value. For example, you could represent the bits of a 32 - bit integer as:
2 31 2 30 2 29 2 28 2 27 2 26 2 25 2 24
2 23 2 22 2 21 2 20 2 19 2 18 2 17 2 16
2 15 2 14 2 13 2 12 2 11 2 10 2 09 2 08
2 07 2 06 2 05 2 04 2 03 2 02 2 01 1
To save space, each group of 8 bits has been added to a new line. The information can then be further
broken down as:
2147483648 1073741824 536870912 268435456 134217728 67108864 33554432 16777216
8388608 4194304 2097152 1048576 524288 262144 131072 65536
32768 16384 8192 4096 2048 1024 512 256
128 64 32 16 8 4 2 1
Chapter 3: Learning the Basics
61
So, to re - examine the original equation, you are actually saying:
(1 + 2 + 4 + 8)
+
(4 + 16)
=
(1 + 2 + 32)
Normally, you will not have to perform math on the bits themselves as performing math with their
numerical equivalents is far easier to understand and just as fast. However, by being able to manipulate
the bits of a value, you can perform certain tricks that help to make your code easier to read while saving
on resources.


Pages:
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155