I have this line:
lsb = (char) (intNumber & 0xff);
and I'm confused as to why is it written like
name = (type) (value)
What does it exactly mean, or what is the purpose of defining a variable like that?
I have this line:
lsb = (char) (intNumber & 0xff);
and I'm confused as to why is it written like
name = (type) (value)
What does it exactly mean, or what is the purpose of defining a variable like that?
lsb = (char) (intNumber & 0xff);
intNumber has been and-ed with 0x11111111
and subsequently typecast to 8-bit character, hence it finds the least significant byte of a variable.
That is the syntax to typecast a variable e.g.:
float x = 5.55;
int y = (int)x; // in this case, the casting would have happened implicitly
// or
printf("%d",(int)x);
// this will display 5
Here by specifying constant/variable will be converted to whatever type you mention inside your first pair of brackets.
That line means you are casting the result given by the expression on the right forcing it to become a char, in order to fit the variable on the left.