Funny nobody thought it necessary to mention the ctype [] array in C / C ++ - also implemented in Java. This concept is extremely useful in processing languages, especially when using different alphabets or when analyzing sentences.
ctype [] is an array of 256 short integers, and in each integer there are bits representing different types of characters. For example, ctype [; A '] - ctype [' Z '] have bits set to indicate that they are uppercase letters of the alphabet; ctype ['0'] - ctype ['9'] have bits to indicate that they are numeric. To see if the character x is alphanumeric, you can write something like "if (ctype [x] and (UC | LC | NUM))", which is somewhat faster and much more elegant than writing "if (" A "= x <= 'Z' || .... '.
Once you start thinking bit by bit, you will find many places to use it. For example, I had two text buffers. I wrote one to the other, replacing all occurrences of FINDstring with REPLACEstring when I went. Then, for the next find-replace pair, I simply switched the buffer indices, so I always wrote from the [in] buffer to buffer [out]. 'in' started as 0, 'out' as 1. After copying was complete, I simply wrote 'in ^ = 1; out ^ = 1; '. And after processing all the notes, I just wrote the [out] buffer to disk, without the need to know what "out" at that time was.
If you think this is low level, think that certain mental errors, such as deja-wu and his twin-jamais-vu, are caused by brain-bit errors!
source share