What is an Illegal octal digit?
Ruby is interpreting numbers that have a leading 0 as being in octal (base 8). Thus the digits 8 and 9 are not valid.
It probably makes more sense to store ZIP codes as strings, instead of as numbers (to avoid having to pad with zeroes whenever you display it), as such: array = ["07001", "07920"]
Rails if statement results in illegal octal digit error?
Starting a number with 0 tells Ruby that it is an octal number. 09 is an illegal octal number since those numbers count from 0 to 7 (and not to 9). So after 07 comes 010 which is 8 in the decimal system, followed by 011 which is decimal 9.
If you want to check if the year is 2009 you could use this check:
<% if @kase.jobno[1,2].to_i == 9 then %>
<img src="../images/2009.jpg" alt="2009">
<% end %>
(so just remove the 0 in front of 09)
C++ illegal digit, simple issue
http://msdn.microsoft.com/en-us/library/00a1awxf(v=vs.80).aspx
Great resource about this.
0xff is hex
0123 is octal
123u is unsigned
..lots more...
Invalid octal digit error
Octal numbers use the digits 0 to 7. Maybe the error could be the digit 9, and digit 8 in your number.
If you want to pass the number '962833', try converting it first to a correct octal number with an online converter. Then add the leading '0' and pass it to your function.
Octal digit in ANSI C grammar (lex)
You want reasonable, user-friendly error messages.
If your lexer accepts 0999
, you can detect an illegal octal digit and output a reasonable message:
int x = 0999;
^
error: illegal octal digit, go back to school
If it doesn't, it will parse this as two separate tokens 0
and 999
and pass them to the parser. The resulting error messages could be quite confusing.
int x = 0999;
^
error: expected ‘,’ or ‘;’ before numeric constant
The invalid program is rejected either way, as it should, however the ostensibly incorrect lex grammar does a better job with error reporting.
This demonstrates that practical grammars built for tools such as lex
or yacc
do not have to correspond exactly to ideal grammars found in language definitions.
Why is 032 different than 32 in Ruby?
What you're seeing is 032
is an octal representation, and 32
is decimal:
>> 032 #=> 26
>> 32 #=> 32
>> "32".to_i(8) #=> 26
>> "32".to_i(10) #=> 32
And, just for completeness, you might need to deal with hexadecimal:
>> 0x32 #=> 50
>> "32".to_i(16) #=> 50
and binary:
>> 0b100000 #=> 32
>> 32.to_s(2) #=> "100000"
Whats wrong with array declaration: invalid digit in octal constant ?
Don't prefix your numbers with 0
, unless you want them treated as octal, which clearly you don't. So just use 8
instead of 08
.
If you're insistent on keeping everything properly aligned, even with single-digit numbers, just use spaces instead of zeros.
Related Topics
Project Euler 1:Find the Sum of All the Multiples of 3 or 5 Below 1000
What's the Point of Argv in Ruby
Changing Table Name at Query Run Time in a Rails Application
Update Just One Gem with Bundler
Parsing Xls and Xlsx (Ms Excel) Files with Ruby
Where's the Best Place to Define a Constant in a Ruby on Rails Application
Get Parent Directory of Current Directory in Ruby
How to Find the Unique Elements in an Array in Ruby
In Rails - Is There a Rails Method to Convert Newlines to <Br>
Get the Value of an Instance Variable Given Its Name
Simple Way of Turning Off Observers During Rake Task
Thread Safety: Class Variables in Ruby
How to Compare Strings Ignoring the Case
How to Check to See If My Array Includes an Object
How to Add Migration with Multiple References to the Same Model in One Table? Ruby/Rails