Geeks Talk

Prepare for your Next Interview




Setting desired bit in a 32 bit number

This is a discussion on Setting desired bit in a 32 bit number within the C and C++ forums, part of the Software Development category; Hi guys, how to set a particular desired bit in a 32 bit number...function should be of format... psedofunct (bit number to set or reset, number to operate on) ...


Go Back   Geeks Talk > Software Development > C and C++

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 12-16-2006
Expert Member
 
Join Date: Oct 2006
Posts: 690
Thanks: 0
Thanked 49 Times in 41 Posts
JobHelper is on a distinguished road
Setting desired bit in a 32 bit number

Hi guys, how to set a particular desired bit in a 32 bit number...function should be of format... psedofunct (bit number to set or reset, number to operate on)

NOTE : This question was asked by pratap, I am posting it in proper forum]
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-09-2007
Junior Member
 
Join Date: Jan 2007
Location: India
Posts: 9
Thanks: 0
Thanked 3 Times in 3 Posts
chandan1008 is on a distinguished road
Re: Setting desired bit in a 32 bit number

guess you can use this macro.
#define SETBIT(bitnumber,number) (number)|(1<<(bitnumber-1))
Reply With Quote
  #3 (permalink)  
Old 02-09-2007
Junior Member
 
Join Date: Jan 2007
Location: India
Posts: 9
Thanks: 0
Thanked 3 Times in 3 Posts
chandan1008 is on a distinguished road
Re: Setting desired bit in a 32 bit number

guess you can use these macros.
#define SETBIT(bitnumber,number) (number)|(1<<(bitnumber-1))
#define RESETBIT(bitnumber,number) (number)&(~(1<<(bitnumber-1)))
Hopefully this helps.
Reply With Quote
Reply

  Geeks Talk > Software Development > C and C++


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
find out the number. jamesravid Brainteasers 7 01-25-2007 11:43 PM
5 digit number.... psuresh1982 Brainteasers 2 11-29-2006 01:49 AM
Can you find the number SriramKrishna Brainteasers 4 10-25-2006 12:56 PM
Pick out the number StephenRaj Brainteasers 2 08-23-2006 04:57 PM
Find the next number RyanJames Brainteasers 2 08-16-2006 06:46 AM


All times are GMT -4. The time now is 05:20 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved