GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Sep-2003, 07:48
Deimos Deimos is offline
New Member
 
Join Date: Sep 2003
Posts: 1
Deimos is an unknown quantity at this point

Masking


int 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  
Old 16-Sep-2003, 09:56
Garth Farley Garth Farley is offline
Awaiting Email Confirmation
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
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 GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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

All times are GMT -6. The time now is 23:12.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.