Shifting Bits
Let ??™ s look at the bits again. If you wanted, you could decide to re - implement the 32 bits of an integer and
put them to another use. For example, it may be that you have four integers you wish to represent in
your application that will never exceed the value 255. Normally, you would simply create four integer
variables and maintain them, but if the four values are grouped by functionality, it seems silly to waste
all that extra memory and code by doing so. Instead, you could mentally partition a single integer value
into four segments, so instead of the previous bit representation, you could envisage the bits as:
128 64 32 16 8 4 2 1
128 64 32 16 8 4 2 1
128 64 32 16 8 4 2 1
128 64 32 16 8 4 2 1
Here, you are still using the same number of bits, only preparing yourself to treat it as four separate
values. The problem remaining, then, is how to store your values into the new structure. Take a look at
your integers:
Int 1 = 155: 00000000 00000000 00000000 10011011
Int 2 = 80: 00000000 00000000 00000000 01010000
Int 3 = 17: 00000000 00000000 00000000 00010001
Int 4 = 131: 00000000 00000000 00000000 10000011
If you simply assign your four different values to the 32 - bit integer, you would be merely repeatedly
overwriting each assigned value with the next.
Pages:
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156