Java provides ways for writing numeric literals in the bases 2, 8, 10 and 16.
I am wondering why base 8 is included, e.g. int x = 0123;
?
I am thinking that there might be something akin to the fact that in hexadecimal the capacity of one byte is FF+1, and so forth.
What are the Uses of Octal Numbers? The Octal Number system is widely used in computer application sectors and digital numbering systems. The computing systems use 16-bit, 32-bit or 64-bit word which is further divided into 8-bits words. The octal number is also used in the aviation sector in the form of a code.
Octal numbers therefore have a range of just “8” digits, (0, 1, 2, 3, 4, 5, 6, 7) making them a Base-8 numbering system and therefore, q is equal to “8”.
The octal numeral system, or oct for short, is the base-8 number system, and uses the digits 0 to 7, that is to say 10octal represents eight and 100octal represents sixty-four.
This answer was written for the original question, "Why is writing a number in base 8 useful?"
It was to make the language familiar to those who knew C etc. Then the question is why support it in those!
There were architectures (various PDPs) which used 18 bit wide words (and others used 36 bit words), so literals where the digit is 3 bits wide would be useful.
Practically, the only place I have seen it used in Java code is for specifying unix-style permissions, e.g. 0777
, 0644
etc.
(The tongue-in-cheek answer to why it is supported is "to get upvotes on this question").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With