Condition as sum of hexadecimal numbers in old Pascal code

I’ve got a very old Pascal program. At the top of the unit is a set of constants looking like:

feature1 = $01; 
feature2 = $02; 
feature3 = $04;
feature4 = $08; 
feature5 = $10;

In database there is a column represents atributes and there is a sum of above features combination. I assume it might be very usefull and even today it let us avoid complicated
conditional block, but i would like to read more about it and see more well explained examples of this type of code. So if you see something like that before i would be appreciated for links to some articles and excercises because i don’t even know what i have to searching for in Google.

  • 2

    This is commonly referred to as bitmasks. In binary those values are 00001, 00010, 00100, 01000, 10000, so you can test for a bit with the and operator, eg. if Value and feature2 <> 0 then ... (feature bit 2 was set).

    – 

Leave a Comment