I have to multiply a byte for the word fixed 10000, and then divide the result by the fixed word 312 (example 73x10000 / 312). How can i do this when the result of the multiplication exceeds the maximum content of a word?
I have to multiply a byte for the word fixed 10000, and then divide the result by the fixed word 312 (example 73x10000 / 312). How can i do this when the result of the multiplication exceeds the maximum content of a word?
dummy_word_var = 73*10000
result_word_var= div32 312
[result=2339]
Or perhapsResult = 2339Code:73 */ 8205
Or, if precision isn't THAT critical, since 10000/312 = 32.0513 which is pretty close to 32:Result = 2336Code:73 << 5
Where obviously the last one will be the smallest and fastes option
/Henrik.
never mind
Last edited by mark_s; - 16th January 2016 at 18:46.
PBP uses internal 32bit register for storing results(registers R1,R2,R3,R4 if I remember correctly). Maximum number that can be stored is 4294967295
Then DIV32 divide register with 312 in this example.
Look into Alexander Avtanski's N-Bit Math which is mentioned in this old post
http://www.picbasic.co.uk/forum/showthread.php?t=12433
Wozzy-2010
Bookmarks