Pages: [1]   Go Down
Author Topic: U & L formatters  (Read 359 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 99
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



Quote
By default, an integer constant is treated as an int with the attendant limitations in values. To specify an integer constant with another data type, follow it with:
a 'u' or 'U' to force the constant into an unsigned data format. Example: 33u
int a=33u
is that mean mean unsigned integer
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50115
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
int a=33u
is that mean mean unsigned integer
Yes. The value 33u will be treated as an unsigned int. Silly to store that in a signed int, then.

Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 99
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is byte data type only for binary representation

which of the following is correct
byte a=B1001;
or
byte a=65;
 
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50115
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is byte data type only for binary representation
The Arduino (and all other computers) only knows how to store data in binary. The compiler is responsible for converting decimal, octal, binary, hexadecimal, etc. representations to binary. So, the answer to your question is no.

Quote
which of the following is correct
Both are correct.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26474
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
which of the following is correct
byte a=B1001;
or
byte a=65;

In Arduino-world, both are correct (though obviously not equivalent), but only the latter is portable.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Shannon Member
****
Karma: 214
Posts: 12412
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
byte a=B1001;
is best avoided, since you can use
Code:
byte a=0b1001;
which isn't Arduino-specific and allows modifiers like
Code:
byte a=0b1001U;

Don't write a long modifier as 'l', always use 'L' since it otherwise is
readily confused with a one.  Consider 1111l and 1111L
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: