0
Extracting an nth bit from a decimal
Forum / Questions & Answers
I'm trying to use the right shift (>>) operator to extract an nth bit from a decimal and its giving me an error: Value was either too large or too small for a UInt16".
Here is an example : 62914560 >> 0
How do I solve this one?
1 reply
-
If you want to do a right shift you can use a combination of the Floor and Pow functions.
Floor(number / Pow(2,shift))
In the case of your example, let's do a right shift of 5 bits:
Floor(62914560 / Pow(2,5)) = 1966080
Which is the same as doing:
62914560 >> 5
This can be used in a calculation or in a value transform.