Hex-Rays' blog

Igor’s tip of the week #83: Decompiler options: default radix – Hex Rays

Written by Igor Skochinsky | Mar 31, 2022

We’ve covered the major pseudocode formatting options previously but there is one more option which can influence the output. It is the radix used for printing numbers in the pseudocode.

In a positional numeral system, the radix or base is the number of unique digits, including the digit zero, used to represent numbers. For example, for the decimal/denary system (the most common system in use today) the radix (base number) is ten, because it uses the ten digits from 0 through 9.

(from Wikipedia)

Automatic radix

The default radix setting is 0, which means “automatic”.

With this setting, the decompiler uses hexadecimal radix for values detected as unsigned, and decimal otherwise. For example, in the below screenshot, arguments to CContextMenuManager::AddMenu() are shown in hex because the function prototype specifies the last argument type as “unsigned int”, while those for LoadStringA() are in decimal because the decompiler used a guessed prototype with the type _DWORD which behaves like a signed type.

“Nice” numbers

In some cases, the decompiler may use hex even for signed numbers if it makes the number look “nice”. Currently (as of IDA 7.7), the following rules are used:

  1. values matching 2n and 2n-1 (typical bitmasks) are printed as hexadecimal.
  2. 64-bit values which have not all-zero or all-one high 32 bits are printed as hexadecimal unless they end with more than 3 zeroes in decimal representation.
  3. -1 is printed as decimal.

Changing the radix manually

You can always change the representation for a specific number in pseudocode from the context menu or via a hotkey.

To toggle between decimal and hex, use the H hotkey. Octal is available only via the context menu by default, but it’s possible to add a custom hotkey for the action name hx:Oct.

Setting preferred radix

By changing Default radix in the decompiler options, you can have decompiler always use decimal (10) or hexadecimal(16) for all numbers without an explicitly set radix. Note that in this case the “nice” number detection will be disabled.

To change the default for all new databases, set the value DEFAULT_RADIX in hexrays.cfg as described in the previous post.

More info: Configuration (Hex-Rays Decompiler User Manual)