|
|
 |
 |
|
Join the Discussion
|
Is this the kind of article that helps you?
Let us know!
|
|
 |
 |
|
|
 |
 |
 |
|
|
 |
After completing this program, I shared it with a programming friend and he pointed out that there was a much easier way to do it! My friend suggested that it was both easier and more efficient to use logical operators and avoid converting to string variables. Specifically, he suggested this code. (Only the color green is illustrated -- red and blue would have similar code.)
Define a constant GreenMask=&hFF00. (But see the second bug below!)
Then the equivalent of (FF - YY) (that is, the hexadecimal value FF minus the hexadecimal value of the Green color) is given by:
(<color representation> Xor GreenMask) And GreenMask
The complete formula for calculating a hexadecimal remainder becomes:
<orig. color> = ((<orig. color> Xor GreenMask) And GreenMask) Or (<orig.color>) And Not GreenMask)
These logical operations might require a little explanation for some of us. But help is on the way. I'm planning a future article specifically focused on the fundamental topic of symbolic logic and Visual Basic programming. Until then, here's how this specific formula works.
First, recall the truth tables for And, Or, Not, and Xor.

As an example using Green, suppose we start with the color (selected quite at random and displayed as an integer value) 8184057
This is equivalent to the Hex value, 7CE0F9 or
- F9 - Red
- E0 - Green
- 7C - Blue
Next page >
The First Bug > Page
1,
2,
3,
4
5,
6,
7
|