How do I remove certain bits from a binary number (Page 1) ● SmileBASIC Source Forums

• #4 ✎ 255 niconii Power User Video Games I like to play video games! Hobbies Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Drawing I like to draw! Hobbies You can use << and >> to shift a number by a given number of bits left or right. So, for example, let's start with &B11. We can shift it like this: ```&B11 << 6 becomes &B11000000 &B11 << 4 becomes &B00110000 &B11 << 2 becomes &B00001100 &B11 << 0 becomes &B00000011 ``` These correspond to SUBPIXEL = 0 through 3, so we can calculate the amount we need to shift to the left as 6 - 2*SUBPIXEL. If we invert these numbers with NOT, we can then AND it with PIXELS to clear the bits for that SUBPIXEL. Then, we just need to shift COLORS by the same amount, and OR it with PIXELS. So, the code ends up looking like this: ```SHIFT = 6 - 2*SUBPIXEL PIXELS = PIXELS AND NOT (&B11 << SHIFT) PIXELS = PIXELS OR (COLOR << SHIFT)``` Posted