var d = 7;
in binary format: 7 = (111)
What I want to do is set the second place on the right to 1 or 0,
and return the decimal value.
For example, if I want to make the second one from 1 to 0, then after the process should return 5,
because 5 = (101).
How to implement this in javascript?
EDIT
The answer should be something like this:
function func(decimal,n_from_right,zero_or_one)
{
}
If the decimal number is the number to be processed, n_from_right is the number of bits to the right, in my example above 2. 2. zero_or_one means that this particular bit is set to 0 or 1.
source
share