Based on your comments:
The value which is being returned from somefunction()
- 101010 - is beyond the range of the uint16_t
variable temp
which you are assigning it to. It is being truncated to 35474 (101010 mod 65536) when it is assigned to that variable, which would cause the results of the division and modulo to be 35 and 474, respectively.
You will need to change the type of temp
to uint32_t
, and change the type of remainder
to uint32_t
as well to avoid truncating the result.