Archived
This forum has been archived. Please start a new discussion on GitHub.
Documentation issues
Comments
-
Unclear section in documentation
Hi Michi,
I may not be enough of a C++ head to know the nuances of integer literals , but this confuses me a bit (from page 69 in the 1.0.2 docs):
• As for C++, integer literals can be specified in decimal, octal, or hexadecimal
notation. For example:
const byte TheAnswer = 42;
const byte TheAnswerInOctal = 052;
const byte TheAnswerInHex = 0x2A; // or 0x2a
Specifically, the "Octal" reference -- what is it that indicates it's 52 octal and not 52 decimal? Does the leading 0 indicate that? I realize this isn't a remedial C++ course but this isn't too clear to me. Perhaps you could put a comment after 052 which indicates what's going on?0 -
Re: Unclear section in documentationOriginally posted by CatOne
const byte TheAnswer = 42;
const byte TheAnswerInOctal = 052;
const byte TheAnswerInHex = 0x2A; // or 0x2a
Specifically, the "Octal" reference -- what is it that indicates it's 52 octal and not 52 decimal? Does the leading 0 indicate that? I realize this isn't a remedial C++ course but this isn't too clear to me. Perhaps you could put a comment after 052 which indicates what's going on?
Well, that's just standard C++ (and C, by the way). An integer literal that starts with a leading zero and is followed by one or more digits in the range 0-7 is interpreted as a literal with base 8.
It's been like this since the day dot in C (which means since about 1970). The octal notation was added to the language because of the DEC PDP machines, which had fields in their instruction set that were three bits or mulitples of three bits wide, making an octal notation more convenient when using machine or assemply language than a hexadecimal notation.
Cheers,
Michi.0