Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are octal numbers (base 8) used for?

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.

like image 354
jokinjo Avatar asked Oct 28 '19 07:10

jokinjo


People also ask

What are octal number system used for?

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.

What are the 8 base digits for octal?

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”.

Which number uses the base 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.


1 Answers

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").

like image 193
Andy Turner Avatar answered Oct 05 '22 00:10

Andy Turner