Hi Alfred,

Getting the compiler to use the precision I needed has posed quite some 
problems. In general, the compiler should use the largest integer type 
of the operands for performing the operation. If key is defined as 
uint16_t, then the calculation should be done in 16-bits (independent of 
the processor used). The result will then be cast to whatever type used 
by the receiving variable (again uin16_t for the variable "result" in 
your case). The value in "result" should be 128.

The only problem that could occur is the default type of constants. If 
you use an 8-bit platform (e.g. MicaX, Iris), the default type might be 
an 8-bit (u)int. In this case, "key = 256;" might result in a wired 
outcome. I've had this while trying to assign 4-byte constants (>65'535) 
on a 16-bit platform (telosb), but this might have involved some 
computation (like 100 * 1024).

If in your example you do not get 128, try setting
"key = (uint16_t)256L;".

Cheers,
Urs


Alfred NOBEL wrote:
> Hi all,
> 
> if I had a "uint16_t key" variable, and if I divide this variable by
> "(uint_8) 2" so in which type will be the result? uint8_t?
> 
> In more detail
> let's say that "key = 256;" and I had "uint16_t result" variable
> 
> so which will be the value of result if I execute something like that result
> = key/2;
> 
> Thanks in advance.
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to