![]() |
|
#1
|
|||
|
|||
Maskingint Mask( int x )
{ } // Mask( ) This function should return an integer with a 1 corresponding to x's least significant 1 bit; read: x's rightmost 1. I can't use control structures, and I can only use the operands ! ~ | ^ & << >> and +. If anyone has any tips, I'd appreciate it. |
|||
|
#2
|
|||
|
|||
|
Oh, I smell a University student.
This is kinda nasty. I remember finding this in a book somewhere. What you do is something like this: You get an integer, say 13 = 1101. The least significant bit is the rightmost bit, i.e. 1, yes (forgot most of this stuff ages ago)? 13 & 1 = 1 - rightmost 12 & 1 = 0 - rightmost (12 = 1100) What this does is compare the following 13 = 1101 & 1 = 0001 =========== 1 = they're the same Hope this helps GF |
Recent GIDBlog
Problems with the Navy (Enlisted) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Redirect multiple URLs to one script, masking true URL | Maccaday | Apache Web Server Forum | 1 | 10-Dec-2003 08:34 |
| Masking | pcxgamer | Open Discussion Forum | 12 | 07-Aug-2003 16:03 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The