iRules number notation converter

Type a value as it appears in an iRule (010, 0x1F, 08, 1e3) and see how Tcl 8.4 reads it: integer or double, the base, the same value in other notations, and why 010 == 8 is true while 010 eq 8 is false. Local, no network.

Reti
Try

Integer written in octal

Tcl prints it as 8

  • A leading 0 makes Tcl read the digits as octal (base 8): 010 is 8 in decimal.
  • This is the classic iRules surprise: a value that looks decimal, such as a zero-padded code or time, is octal because of its leading 0.

The same integer in other notations

NotationDigitsHow to write it in an iRule
Decimal88
Hexadecimal80x8
Octal10010
Binary1000Tcl 8.4 has no binary notation

Two places Tcl reads numbers

Written in the expression itself

expr {010}

8

A literal is read when the expression is compiled, so a bad one (such as 08) stops the whole expression before anything in it runs.

Held in a variable

set x 010
expr {$x + 0}

8

A value is read only when an operator needs a number. If it cannot be read, arithmetic fails at that point, and comparisons quietly compare text instead.

Comparing it with 8

ExpressionResultWhy
expr {$x == $y}1Numeric when both sides read as numbers; otherwise the text is compared.
expr {$x eq $y}0eq always compares the text.
expr {$x < $y}0Numeric when both sides read as numbers; otherwise the text is compared.
expr {$x > $y}0Numeric when both sides read as numbers; otherwise the text is compared.

In these expressions $x holds 010 and $y holds 8, both set as plain values.

API endpointGEThttps://ronutz.com/api/v1/f5-irules-number-notationDocumented, not served. Opens the specification.

Riferimenti

Appears in these workflows