mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-09-20 07:43:04 +08:00
Merge 4debd208a9
into ca3d16dcce
This commit is contained in:
commit
bbb86202fc
13
src/algorithms/math/bits/extractBits.js
Normal file
13
src/algorithms/math/bits/extractBits.js
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @param {number, number, number}
|
||||
* @return {number}
|
||||
*/
|
||||
|
||||
|
||||
/* Function to extract 'k' bits from position 'p'
|
||||
* and returns the extracted value.
|
||||
*
|
||||
*/
|
||||
export default function extractBits(number, k, p) {
|
||||
return (((1 << k) - 1) & (number >> (p - 1)));
|
||||
}
|
Loading…
Reference in New Issue
Block a user