Questions tagged [octal]

The octal numeral system, or oct for short, is the base-8 numeral system, using the digits 0 to 7. Often used to notate Unix permissions. It has also used to store the on/off state of digital seven-segment displays.

The octal numeral system, or oct for short, is the base-8 numeral system, using the digits 0 to 7.

More on the use of octal in computing.

Related tags

419 questions
348
votes
3 answers

Is 0 a decimal literal or an octal literal?

Zero is always zero, so it doesn't matter. But in a recent discussion with a friend he said that octal literals are almost unused today.† Then it dawned upon me that actually almost all integer literals in my code are octal, namely 0. Is 0 an octal…
Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
285
votes
10 answers

How do I work around JavaScript's parseInt octal behavior?

Try executing the following in JavaScript: parseInt('01'); //equals 1 parseInt('02'); //equals 2 parseInt('03'); //equals 3 parseInt('04'); //equals 4 parseInt('05'); //equals 5 parseInt('06'); //equals 6 parseInt('07'); //equals 7 parseInt('08');…
Portman
  • 31,785
  • 25
  • 82
  • 101
85
votes
3 answers

What are the Java semantics of an escaped number in a character literal, e.g. '\15' ?

Please explain what, exactly, happens when the following sections of code are executed: int a='\15'; System.out.println(a); this prints out 13; int a='\25'; System.out.println(a); this prints out 21; int a='\100'; System.out.println(a); this…
VAr
  • 2,551
  • 1
  • 27
  • 40
62
votes
6 answers

Is 0 an octal or a decimal in C?

I have read this. It's octal in C++ and decimal in Java. But no description about C? Is it going to make any difference if 0 is octal or decimal? This is the question asked by my interviewer. I said no and I explained that it is always 0 regardless…
Gibbs
  • 21,904
  • 13
  • 74
  • 138
59
votes
1 answer

Invalid Token when using Octal numbers

I'm a beginner in python and I'm trying to use a octal number in my script, but when I try it, it returns me that error: >>> a = 010 SyntaxError: invalid token (, line 1) >>> 01 SyntaxError: invalid token (, line 1) There's…
Rafael
  • 593
  • 1
  • 4
  • 5
42
votes
9 answers

In what situations is octal base used?

I've seen binary and hex used quite often but never octal. Yet octal has it's own convention for being used in some languages (ie, a leading 0 indicating octal base). When is octal used? What are some typical situations when one would use octal or…
Bob
  • 7,851
  • 5
  • 36
  • 48
29
votes
6 answers

Why are Octal numeric literals not allowed in strict mode (and what is the workaround?)

Why are Octal numeric literals not allowed in JavaScript strict mode? What is the harm? "use strict"; var x = 010; //Uncaught SyntaxError: Octal literals are not allowed in strict mode.

Check browser console for errors

In case a…
Zameer Ansari
  • 28,977
  • 24
  • 140
  • 219
25
votes
4 answers

Parse error: Invalid numeric literal

I have the following error while running this code below: Code: Error: Parse error: Invalid numeric literal. Why this issue occurred and how do i solve this?
Rana Ghosh
  • 4,514
  • 5
  • 23
  • 40
23
votes
3 answers

Why are leading zeroes used to represent octal numbers?

I've always wondered why leading zeroes (0) are used to represent octal numbers, instead of — for example — 0o. The use of 0o would be just as helpful, but would not cause as many problems as leading 0es (e.g. parseInt('08'); in JavaScript). What…
Hauleth
  • 22,873
  • 4
  • 61
  • 112
22
votes
7 answers

Where did the octal/hex notations come from?

After all of this time, I've never thought to ask this question; I understand this came from c++, but what was the reasoning behind it: Specify decimal numbers as you normally would Specify octal numbers by a leading 0 Specify hexadecimal numbers…
John
  • 17,163
  • 16
  • 65
  • 83
16
votes
3 answers

Scala 2.10 - Octal escape is deprecated - how to do octal idiomatically now?

See https://issues.scala-lang.org/browse/SI-5205 and https://github.com/scala/scala-dist/pull/20 Octal escape value leading 0 has been deprecated from scala and I don't see an idiomatic alternative. How do you deal with octals in scala 2.10 now??…
JasonG
  • 5,794
  • 4
  • 39
  • 67
15
votes
3 answers

Python: Invalid Token

Some of you may recognize this as Project Euler's problem number 11. The one with the grid. I'm trying to replicate the grid in a large multidimensional array, But it's giving me a syntax error and i'm not sure why grid = [ [ 08, 02, 22, 97, 38,…
The.Anti.9
  • 43,474
  • 48
  • 123
  • 161
15
votes
1 answer

Can I customize syntax highlighting in Eclipse to show octal literals differently?

I think octal literals are Very Dangerous Things™, and I'd like them to be glaringly obvious whenever I read source codes. There must be a way to do this in Eclipse, right? So it looks like standard Eclipse cannot be configured to do this? A custom…
polygenelubricants
  • 376,812
  • 128
  • 561
  • 623
13
votes
4 answers

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…
jokinjo
  • 147
  • 1
  • 6
13
votes
3 answers

Value too great for base (error token is "0925")

I have the following logic in my bash script: #!/bin/bash local_time=$(date +%H%M) if (( ( local_time > 1430 && local_time < 2230 ) || ( local_time > 0300 && local_time < 0430 ) )); then # do something fi Every now and then, I get the error…
oompahloompah
  • 9,087
  • 19
  • 62
  • 90
1
2 3
27 28