My learning thread - thanks everyone
Wed Jan 19 2011, 10:59 pm
guys. another question..
what is the exact explanation why we use like this
what actually the effect of s32? what is the difference is i use s16?
what is the exact explanation why we use like this
variable1 = (s32)variable2;
what actually the effect of s32? what is the difference is i use s16?
Thu Jan 20 2011, 02:40 am
what actually the effect of s32? what is the difference is i use s16?romel_emperado
(s32) is a "cast".. usually used when you transfer a value between variables of different sizes.
It tells the compiler that you know about the miss-match and take responsibility for any errors.
In this case variable1 is a 32 bit signed variable and variable2 isn't.
The effect of using (s16) will depend on what variable2 is, and the compiler may object.
romel_emperado like this.
Thu Jan 20 2011, 03:59 am
(s32) is a "cast".. usually used when you transfer a value between variables of different sizes.
It tells the compiler that you know about the miss-match and take responsibility for any errors
thanks experimenterUK
Fri Jan 21 2011, 03:15 pm
guys what is the purpose of adding bitwise AND 0x0FF in the expresion below?
for example if the sAlt.altitude = 111
in binary 111 is 0110 1111 so
so what is the purpose of 0xFF ??
for example if the sAlt.altitude = 111
in binary 111 is 0110 1111 so
0110 1111
1111 1111
___________
0110 1111 ---answer is still 0110 1111
so what is the purpose of 0xFF ??
temp[3] = sAlt.altitude & 0xFF;
Fri Jan 21 2011, 08:49 pm
temp is a byte array (i byte per element) and altitude might be a s16 (a 16 bit variable) so you have to send this variable in parts to store it a byte array.
sAlt.altitude & 0xFF will truncate/mask the upper 8 bits of variable and lower 8bits will be stored in temp array.
0x1234 & 0xFF = 0x34
0x1234 & 0xFF00 = 0x1200 //truncate lower 8 bytes.
sAlt.altitude & 0xFF will truncate/mask the upper 8 bits of variable and lower 8bits will be stored in temp array.
0x1234 & 0xFF = 0x34
0x1234 & 0xFF00 = 0x1200 //truncate lower 8 bytes.
Fri Jan 21 2011, 09:24 pm
thanks for the explaination ajay. Another knowledge
How did you study like that before? Your awesome! Hehe
How did you study like that before? Your awesome! Hehe
Fri Jan 21 2011, 10:14 pm
haha thanks! i will
i will be engaged a lot of practice because some projects are approaching..
I'll ask again here if i have some doubts. Hehe
i will be engaged a lot of practice because some projects are approaching..
I'll ask again here if i have some doubts. Hehe
Sat Jan 29 2011, 05:50 am
guys I have question..
Im how do I accurately count/determine the maximum value it can hold of this data type?
Im how do I accurately count/determine the maximum value it can hold of this data type?
u8 = unsigned char
s8 = char
u16 = unsigned short / unsigned int
s16 = short / int
u32 = unsigned long
s32 = long
Powered by e107 Forum System