OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Bit manipulation utility functions

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Tue Jun 08, 2004 5:59 am    Post subject: Bit manipulation utility functions Reply with quote

Code:
' Return True if a particular bit in nBits is set.
' Bit 0 is the least significant bit.
Function IsBitSet( ByVal nBits As Long, ByVal nBitNum As Integer ) As Boolean
   IsBitSet = GetBitNum( nBits, nBitNum ) > 0
End Function


' Return a particular bit from nBits.
' Bit 0 is the least significant bit.
Function GetBitNum( ByVal nBits As Long, ByVal nBitNum As Integer ) As Long
   Do While nBitNum > 0
      nBitNum = nBitNum - 1
      nBits = Int( nBits / 2 ) ' shift right
   Loop
   GetBitNum = nBits Mod 2
End Function



' Set a particular bit in nBits.
' It does not matter what the previous status of the bit was,
'  end ends up as a 1 bit.
' Bit 0 is the least significant bit.
Function SetBit( ByVal nBits As Long, ByVal nBitNum As Integer ) As Long
   nBit = 1
   Do While nBitNum > 0
      nBitNum = nBitNum - 1
      nBit = nBit * 2 ' shift left
   Loop
   SetBit = nBits Or nBit
End Function



' Clear a particular bit in nBits.
' It does not matter what the previous status of the bit was,
'  end ends up as a 0 bit.
' Bit 0 is the least significant bit.
Function ClearBit( ByVal nBits As Long, ByVal nBitNum As Integer ) As Long
   Dim nBit As Long
   nBit = 1
   Do While nBitNum > 0
      nBitNum = nBitNum - 1
      nBit = nBit * 2 ' shift left
   Loop
   ClearBit = nBits And (Not nBit)
End Function


2005-04-02
The latest version of this code is at....
http://www.oooforum.org/forum/viewtopic.phtml?p=73055#73055
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
freshkaa
Newbie
Newbie


Joined: 06 Mar 2010
Posts: 1

PostPosted: Wed Mar 10, 2010 1:31 am    Post subject: Reply with quote

What should I do about an ex-boyfriend who keeps blaming me? My ex-boyfriend keeps blaming me for the problems he's having now. He says that he's lost friends due to the fact that we were dating, but I didn't do anything to his friends, or even once suggest that I didn't like those friends. He also says that my life is perfect and happy and his is horrible, but I was the one there talking with him for hours at night trying to comfort him, while I couldn't get out more than 4 sentences about the problems I was having.
_______________________
asian marriage
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group