Go Down

Topic: Forcing Data Types (Read 663 times) previous topic - next topic

redmiata

Sorry if this seems too simple, but why do I get different results when passing '040' and '40' as an argument?
I'm programming a lathe and arguments are in 1/1000th inches, so '040' is much easier to read.
Thanks,
  redmiata

Quote


void a_function(int variable_1, int variable_2) {
  Serial.print("variable_1 = ");Serial.println(variable_1);
  Serial.print("variable_2 = ");Serial.println(variable_2);
}

void setup (){
  Serial.begin(9600);
}

void loop(){ 
  a_function(040,40);
  a_function(40,040);
  delay(10000);
}


dxw00d

Numbers with a leading zero, like 040, are read by the compiler as octal (base 8 ).

PaulS

Quote
I'm programming a lathe and arguments are in 1/1000th inches, so '040' is much easier to read.

Much easier than what? " 40" looks better to me. And the compiler, if that's important. (Without the quotes, of course.)

redmiata

I understand the programming error now thanks to dxw00d...
In machining referring to a measurement as "040" (oh-four-oh) is understood to mean 40/1000 or forty thousandths.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy