I’m writing a program in which i require to normalise an 18-bit input between 0-9999. This is something i have never come across before,
I have searched the internet and correct me if i am wrong here, but is this as simple as converting the 18-bit binary(000000000000000000) input into a natural number and then divide it by 1000.
Is there is a different and more efficient method ????
Thank you
No, what you want to do is multiply your input by
0.03814697265.The reasoning is pretty simple: you take your range of inputs (
0..2^18) and split it in10000“slices”. Thus each slice will have a range of just over26. Then if you divide your input from the original range by this26(or multiply it by1/26), you’ll get your number in the0..9999range.Edit: depending on your background, you may need to know that here I use
^with the meaning of exponentiation. Might be moot since this question is tagged C and it has no first-class concept of exponentiation, but it’s definetly not XOR!