Hex Editor - Binary File Editing Software for Windows
Docs

Enumerations

Hex Editor Neo supports the special form of integer constants, called enumerations.

Syntax:

// legacy syntax:        
enum [name-id[<integer-type>]]
{
    value-id [ = const-expression]
    [, value-id [ = const-expression] …
    ]
};

// new syntax
enum [name-id[ : integer-type]]
{
    value-id [ = const-expression]
    [, value-id [ = const-expression] …
    ]
};

Enumeration may optionally have a name and a type. If name is omitted, a nameless enumeration is created. If type is omitted, it is defaulted to int.

An expression, if specified, must be a constant expression, that is, its value must be calculable at the compile-time. You may use immediates, constants and other previously defined enumerations as well as sizeof() operator in its static form.

If expression is omitted, the value of the current element is computed as a value of the previous element plus one. If this is a first enumeration element, its value will be 0:

enum MyEnum : unsigned
{
    FirstValue,                               // defaulted to 0
    SecondValue,                              // defaulted to 1
    ThirdValue = 5,                           // overridden, equals 5
    FourthValue,                              // defaulted to 6
    FifthValue = ThirdValue - SecondValue,    // equals to 4
};

An enumeration does not create its own scope and places all values in the parent scope.

enum MyEnum
{
    FirstValue            =0x00000010,
    SecondValue           =0x00000020
};

const test = FirstValue;   // valid, as FirstValue (and SecondValue) are placed in the global scope, parent to MyEnum's scope

Using Enumerations

You may use named enumerations as types for fields in user-defined types. If you do this, Hex Editor Neo will automatically recognize the enumeration value when the structure is bound to the data. For example:

enum MyFlags : unsigned
{
    FIRST_BIT_SET      =0x00000001,
    SECOND_BIT_SET     =0x00000002,
};

struct A
{
    MyFlags flags;
};

When you bind structure A to data, flags gets visualized as following:

Data ValueDisplay
1FIRST_BIT_SET
2SECOND_BIT_SET
00
3FIRST_BIT_SETSECOND_BIT_SET
5FIRST_BIT_SET4
88

Hex Editor Neo automatically parses the enumeration value and displays its symbolic name (or names).