Compute Bit Mask


Closed Thread
Results 1 to 2 of 2
  1. #1
    harmand's Avatar
    harmand Guest

    Default Compute Bit Mask

    I have a app in vb.net that I am doing maintenance on and as always not enough documentation.

    The app is for a Human Machine Interface that uses a visioning system to look for pins when a curcuit board is placed in a ficture. When the value comes out of the PLC the leading 3 bits must be set to 0 and the result is compared to a value in a DB table.

    I used a BitArray and a StreamWriter to come up with a string rep of the number 47;

    '0000000000101111'

    I know that the MSB is at pos 11.

    I want to set the bit mask in the form 'And 2 ^ x'.

    How do I compute x?

    Or am I going about this the wrong way.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    I still don't use .net, so I don't know the NEW, IMPROVED syntax of it all...
    (VB6 'till the end!!!)

    x = bit position to be set to a 1
    y = value in which a bit is to be set
    y = y + ( 2 ^ x )
    or
    y = y OR ( 2 ^ x )

    If you're bit is at position 11, then your value is 2 ^ 11, or 2048 (2^11)...
    If the original value is 47 00000101111
    and you add 2048 (2 ^11)
    you get
    2095 or 100000101111

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Doubt with interrupt on change
    By lugo.p in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th March 2010, 15:22
  3. Sleep Mode
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th March 2008, 10:31
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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