Results 1 to 5 of 5

Thread: Bits

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    68

    Talking

    Hi,


    Can someone explain to me how to perform bit Manipulation and comparison in VB.

    I have used it in Delphi, but have never had to in VB until now...

    I have an integer field in a DB that has certain bits set to specify certain criteria.

    I need to be able to check bits, and set them...

    THE DOUGSTER!!!!!!


    *-MCSD-*

  2. #2
    Addicted Member Geoff Gunson's Avatar
    Join Date
    Jun 1999
    Posts
    241
    Hi

    I am assuming that you allready know the basics of binary and hex.

    So.....

    To do a comparision to check if a single bit in a byte, int or what ever you can use the logical And operator with a bit mask.

    To toggle a single bit with in a value you use the Or operator.

    i.e. &H7F Or &H80 = &hFF or in other words

    0111 1111
    OR
    1000 0000
    =
    1111 1111

    HTH

    Geoff


  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Similary you can use these operators for bit manipulation: Xor or Eqv(to invert bits) And (to set bits to 0) Or (to set bits to 1) Not (to invert all bits) and imp (implication)
    You can operate several bits at the same time, since the comparation is bitwise, for instance 11110 and 10101 is 10100.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    Note that these operators will work with any numerical values, not just Hex representations... it will cast to an integer type before performing the comparison though so do not bother using fractional parts...

    kedaman - What is Imp, never come across that before - looks evil (geddit?)

    Cheers,

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    EVIL! EVIL! EVIL!

    Imp.. hehe, nope probably not evil even if it sounds evil. But you probably don't need to use it, there was a thread a while back about the implication operator and it proved to be useful in some special cases
    0 imp 0 = 1
    0 imp 1 = 1
    1 imp 0 = 0
    1 imp 1 = 1
    false implicates always true, it just skips the second operand, otherways it returns the second operand.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width