Bitwise¶

This section of the library includes components for working with integer values as bit vectors. These components are built using the basic bitwise primitives in CertSAFE such as Bitwise AND and Bitwise Shift. All of the components in this section follow the convention that the lowest-order bit of an integer is numbered 0, followed by 1, 2, 3, etc. for higher-order bits.

The example components assign inputs representing bit indices a data type of UInt8. Fixing these inputs to a specific data type, rather than leaving them polymorphic, makes it possible to connect literals to these pins without having to add a data type annotation each time. The annotation specifying the data type as UInt8 is located in the implementation of the Bit Mask component, with all of the other definitions inferring their data types from that.

The Bit Mask component accepts a bit index and outputs a mask value that has a 1 at the specified bit and 0 everywhere else. It is used in the implementation of the Test Bit component and the Set Bit, Clear Bit, and Toggle Bit components, and can also be used in your own bit manipulation logic.

Test Bit¶

The Test Bit component checks whether a specified bit in an integer value is set. It outputs True if the selected bit is 1 and False if the selected bit is 0.

Set Bit, Clear Bit, and Toggle Bit¶

These components take in an integer value and output that value with a single bit modified. The Set Bit component changes the specified bit to 1 unconditionally. The Clear Bit component changes the specified bit to 0 unconditionally. The Toggle Bit component sets the specified bit to 1 if it is currently 0, or 0 if it is currently 1.

Update Bit¶

The Update Bit component is similar to the Set Bit, Clear Bit, and Toggle Bit components, except that it has an input that specifies what the new value of the bit will be. This component is implemented simply by switching between the output of Set Bit and Clear Bit.

Extract Field¶

The Extract Field component pulls out all of the bits in a specified range from an input integer value. It is useful when breaking down messages or other packed binary structures. The component uses shifting and masking to obtain only the bits in the range low bit to high bit, inclusive.