2

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
Ethan Heilman
  • 16,347
  • 11
  • 61
  • 88
Bob
  • 47
  • 4
  • 8

4 Answers4

2

convert each of the digits one at a time, into 4-bit binary.

80000000 -> 1000 0000 ....
50A00000 -> 0101 0000 1010 ...
Anirudh Ramanathan
  • 46,179
  • 22
  • 132
  • 191
2

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

Community
  • 1
  • 1
1

The example seems right. They just reversed the most significant and least significant bits around, and used a 1-based index for bit positions (apart from keeping the data in ASCII instead of 4 bytes of hex). So, if bit n is set (LSB being bit #0, or the value 00000001), you get seat number 31-n+1.

vhallac
  • 13,301
  • 3
  • 25
  • 36
  • I still don't see how `80000000` is `1` – trutheality Jun 07 '11 at 19:44
  • I've known some people who were very obsessive about keeping their data human readable. So (probably) instead of 256 values per byte, the people who wrote the spec chose to have 16 values per byte (0-f), and they probably represent as straight ASCII values. – vhallac Jun 07 '11 at 19:50
1

Your masks are the following:

Seat 1: 0x80000000
Seat 2: 0x40000000
Seat 3: 0x20000000
Seat 4: 0x10000000
Seat 5: 0x08000000
...
Seat 31:0x00000002
Seat 32:0x00000001

Or more general:

mask = 1 << (32 - seatno)

Example:

0x50A00000 = 0x40000000 | 0x10000000 | 0x00800000 | 0x00200000

hence seat 2, 4, 9 and eleven.

Hyperboreus
  • 31,997
  • 9
  • 47
  • 87