Search code examples
bitmaskbit-masks

Bit Mask Question


Readng the documentation for a point of sale system, here is the example they give for a mask that is supposed to tell you what seats are selected. I can't figure this out. I completely understand bit masking. Is this example just wrong?

Function

This system variable is an eight character string that contains the seat filter mask.

Type/Size

A8

Syntax

@Filter_mask

Filter_mask Usage

This system variable is Read-Only.

Filter_mask Example

The following is an example of a filter mask:

80000000 - seat 1 is active (@filter_active ="Y")
00000001 - seat 32 is active (@filter_active = "Y")
50A00000 - seats 2,4,9 and 11 are active (@filter_active = "Y")
00000000 - filter inactive, no seats

Solution

  • These are 8-digit hexadecimal numbers, which can store as much as a 32-digit binary number.

    (16^8 = 2^32 = 4,294,967,296)

    In a binary representation, each digit corresponds to a seat:

       hex               binary
    80000000 = 10000000000000000000000000000000
    00000001 = 00000000000000000000000000000001
    50a00000 = 01010000101000000000000000000000
    00000000 = 00000000000000000000000000000000
    

    The first binary bit is for seat #1, and the last is for seat #32. Since they're giving you an 8-character string, you'll probably want to parse it into a 32-bit value to do the masking arithmetic. Look for "hex string to integer" in your target language and you'll find something like:

    Convert hex string to int in Python

    Note: Google can do base conversions off the cuff for you when you're looking at things like this, such as ("0x50a00000 in binary"), but Wolfram Alpha does a bit more:

    http://www.wolframalpha.com/examples/NumberBases.html