I am writing a function to expand a signed number to a wider bit length. This is a very commonly used action in the PowerPC command set. This is what I have so far:
function exts(value, from, to) { return (value | something_goes_here); }
value is integer input, from is the number of bits that value uses, and to is the length of the target bit.
What is the most efficient way to create a number with to - from bits set to 1 , followed by from bits set to 0 ?
Ignoring the fact that JavaScript does not have the syntax of number 0b , for example, if I called
exts(0b1010101010, 10, 14)
I would like the OR function to have a value with 0b11110000000000 , returning a result with a character extension of 0b11111010101010 .
source share