Loading...
Logo
Processing Forum
Why this does not work?

Copy code
  1. void setup(){
  2. int s = 08;
  3. }

but this does...

Copy code
  1. void setup(){
  2. int s = 07;
  3. }

??

Replies(7)

Octal numbers don't have digits 8 & 9. Their range is from 0 until 7!
Any number prefixed w/ leading 0(s) is interpreted as an octal literal!

A quick example...
Octal literal 0400 = decimal literal 256:

int s = 000400;
println(s);
exit();

Hummm octal wtf!! I want decimal ints. Thanks for explaining.  I was getting a video time code string like "12:43:34:20", spliting and converting to ints to do some math... When I had, for instance, "00:10:10:09" i felt in this octal world with "unexpected token 9" error, i guess i need to check for a leading zero... can it be, kind of,  casted? Thanks.
I believe function int() can act as a trustful converter, bypassing the dangerous initial leading zeros.
Dunno why your conversion coulda fallen into an octal trap though!   
Copy code
    int octal = 000400;
    println(octal);
    
    String s = "000400";
    println(s);
    
    int decimal = int(s);
    println(decimal);
    
    exit();
    
Thanks, i have tried this, but unsuccessfully, now, after your example I found my mistake somewhere else.
Happens that i made a TimeCode class, with two constructors, one takes a string, other takes a int to initialize the time code to that time.  Either a string "00123019" or an int 00123019, were position would indicates if means hours, minutes, seconds or frames, like color in Processing "HHMMSSFF", but bumped on this... I'll see... Thanks again. 
See also https://forum.processing.org/topic/issue-with-integer-division-of-zero-padded-integers
Funny how some topics come close in time, even if from unrelated paths.
Very true, PhiLho! In this month only, there were 2 other posts mentioning octals; even though it was myself who introduced this curious subject!   (^_^):

need-help-with-color-program

processing-2-0-changed-how-pixels-works
What do I need octal for...   Thanks guys. I sticked to strings to pass time code values.