Bit Fields

Overview | Bit Field Responses | Interpreting Responses

Overview

Alegeus uses bit fields within our REST APIs to enhance efficiency and performance. Bit fields store multiple Boolean responses in a single integer response. Each true/false option corresponds to a binary digit, and by combining these digits in different ways, you can represent any option of combinations that you want.

The example below shows a collection of 15 Boolean response fields (left) represented by a single bit field (right).

Understanding a bit field response

The bit field response integer, ('6005' in the example provided) is able to communicate which fields in a collection are true, and which are false. This is done through bitwise operations.

Rather than expressing true/false values, each option within the collection is assigned a numerical value. The table below shows the binary values that have been assigned to each option.

Creating a value for a bit field involves taking the logical OR (|) of all individual values to be included in the bit field. The binary values of each option are added together to create the bit field response integer, but only for options that are true. Options that are false are not added towards this count.

Identifying 'true' options

When receiving a bit field response, you can determine which values make up the integer by taking your binary list, identifying the highest possible value that is less than or equal to the integer, and marking that value as 'true'. Next, subtract that value from integer, and repeat the process with the resulting number.

In the image below, you can see that 'AccountDetails_BalanceSummary' is the greatest value that is less than or equal to '6005'. This tells you that 'AccountDetails_BalanceSummary' is 'true'.  There remaining integer is '1909' (6005-4096). The next value less than or equal to your remainder, '1909' is 'RecentTransaction_Status'.

Confirming whether or not a particular option is 'true'

If you want to determine whether or not a specific option is 'true', you can do this by comparing the bit field with the value you want to test using a logical AND operator typically represented by an ampersand (&). If the result is identical to the test value, then the option is 'true'. If the result is zero, then the option is 'false'.

You can learn more about bit fields and bitwise operations here.

Copyright © 2023 Alegeus Technologies, LLC. All rights reserved. Alegeus, Alegeus Technologies, WealthCare, WealthCare Saver are registered trademarks of Alegeus Technologies, LLC