![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| ||||
| I'm going to give this code in 2 posts. In this post, the form would store the users' preference. PHP Code: |
| ||||
| This would be the search form. This code isn't tested, just composed on the fly, but it should give a sufficient idea of what I was discussing. PHP Code: |
| ||||
| I agree, it is a very great solution. However, It still have there own disadvantage. For example: I am run my own clothes shop. My shop sell many shirt with many difference colour. There are Red, Yellow, Black, White and Blue. Now my customers check my website and search for shirt which is can be Red, Yellow, Black, and it can be mix with those three colour. So the possible outcome is: R,Y,B,RY,RB,YB,RYB. In this case you using binary isn't so effective. Imagine if there are over 20 of difference options can be select more than one and you want to search with keyword OR instead of AND and it is going to be insane. |
| ||||
| Quote:
|
| |||
| Quote:
1 = Blue 2 = Green 4 = Red 8 = Brightness Using that alone, you can have a 16-color palette: 0 = Black (0|0|0|0) 1 = Blue (0|0|0|1) 2 = Green (0|0|1|0) 3 = Cyan (0|0|1|1) 4 = Red (0|1|0|0) 5 = Magenta/Violet/Purple (0|1|0|1) 6 = Yellow* (0|1|1|0) 7 = White (0|1|1|1) 8 = Grey (1|0|0|0) 9 = Bright blue (1|0|0|1) 10 = Bright green (1|0|1|0) 11 = Bright cyan (1|0|1|1) 12 = Bright red (1|1|0|0) 13 = Bright magenta (1|1|0|1) 14 = Bright yellow (1|1|1|0) 15 = Bright white (1|1|1|1) * - In QBasic, color 6 was actually brown, which was a "hacked" color because there is a pattern to the values when matched with their corresponding RGB values of HTML, CSS, Photoshop, etc. Notice how it was all 1s and 0s? Think of it this way: 0 = off, 1 = on. If the number at the spot is 1, that color is turned on. If it is 0, it is turned off. Also note the following: (8|4|2|1) Remember the basic colors discussed earlier? The 1s and 0s simply mean: 0 * brightness | 1 * red | 1 * green | 0 * blue = 0*8 | 1*4 | 1*2 | 0*1, which is 6 because 0 + 4 + 2 + 0 = 6 (yellow). This means that yellow is a mixture of red and green. Back to the mask idea, suppose you wanted to fetch the BrRGB values individually for some sort of object or structure. All you would need to use is the equivalent statement in your programming language: Code: <** And in this case refers to a bitwise AND, commonly represented in C/C++, Java and PHP, as well as other programming languages, by the ampersand (&) **> color = 9 <** 9 is bright blue, remember? **> bright = (color And 8) red = (color And 4) green = (color And 2) blue = (color And 1) color = bright Or red Or green Or blue To understand why that works would require more in-depth knowledge of binary and bitwise operations, something that is beyond the scope of this post. For more information, check out one or more of the following sites: PHP Bitwise Tutorial by Jim Plush - Talks about binary and bitwise operations in PHP; note that variables in PHP are things like "$a" or "$hello" rather than just "a" or "hello". GameDev.net - Bitwise Operations in C - Talks about bitwise operators in C, various uses as applied to game development, etc. |
| ||||
| I think we went too far from the topic. I didn't disagree that math isn't important in application. However, It just some application is use it more than some other. Basically, some application doesn't require advanced math. I remember maybe 6 years old, I made a Syntax Editor(which heighlight your code into readable colour) and I didn't use any advanced math(I did use some math operators but it is what we have learn since we were a kid). Futhermore, most of high-level programming langauge nowaday make it more easier for people who have poor math background. In conclusion, every application need math but it is just matter of less or more. Last but not least, even those you have great math background but without technique or experience of programming, it still difficult to solve some problem. |
| ||||
| ROFLMFAO, rpgfan3233. You're going to give a non-math nerd that reads that a heart attack! Having been programming for awhile, I found it interesting that you cited QBasic. Do you know if you assertions hold for gw-basic and Apple IIE BASIC? Time to peek -16384 and seriously frighten the mathless away.Quote:
Quote:
|
| ||||
| I've split off the binary and options discussion to its own thread at Options & Binary Optimization . |
| ||||
| Quote:
I thought it interesting that just yesterday I needed this mathematical logic to resolve a case where I had a statement isomorphic to this: Code: if (A == a && (B != b || C != c)) {
//Do something
} Code: if (A != a || (B == b && C == c)) {
//Do something else
} Code: if (!(A == a && (B != b || C != c))) {
//Do something
} |
![]() |