(This article is a multipost with Go to the Horizon)
There are three main grammars for noting octal numbers.
(The second and third are confusing, but they are zero o
[^ octet])
0
(eg 0123
)0o
as a prefix (eg 0o123
)0O
as a prefix (eg 0O123
)Of these, the table summarizes which grammar each programming language uses.
language | 0 |
0o |
0O |
---|---|---|---|
C | ○ | × | × |
PHP | ○ | × | × |
Perl | ○ | × | × |
Java | ○ | × | × |
Scala (~2.9) | ○ | × | × |
Scala (2.10~) | × | × | × |
Kotlin | × | × | × |
C# | × | × | × |
Rust | × | ○ | × |
Swift | × | ○ | × |
Go | ○ | ○ | ○ |
Ruby | ○ | ○ | ○ |
Python2 | ○ | ○ | ○ |
Python3 | × | ○ | ○ |
JavaScript[^js] | ○ | ○ | ○ |
0
0
but stopped0o
has been adopted."I write the octal number as 0123
"may be old.
[^ octet]: octet (8-piece set) o [^ js]: However, if 0 is followed by 8 or 9, it is a decimal number. Reference: lexical grammar --JavaScript | MDN
Recommended Posts