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.
AğTry
Integer written in octal
Tcl prints it as 8
- A leading 0 makes Tcl read the digits as octal (base 8):
010is 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
| Notation | Digits | How to write it in an iRule |
|---|---|---|
| Decimal | 8 | 8 |
| Hexadecimal | 8 | 0x8 |
| Octal | 10 | 010 |
| Binary | 1000 | Tcl 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
| Expression | Result | Why |
|---|---|---|
expr {$x == $y} | 1 | Numeric when both sides read as numbers; otherwise the text is compared. |
expr {$x eq $y} | 0 | eq always compares the text. |
expr {$x < $y} | 0 | Numeric when both sides read as numbers; otherwise the text is compared. |
expr {$x > $y} | 0 | Numeric 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.