I need the definition of a function $s(v,p,w) = i$ where $v$ is an integer that can be expressed as binary or decimal, $p$ is the position of a bit in $v$, and $w$ is an amount of bit from 1 to $n$. The function return $i$, another integer that corresponds to the $w$'s bits at position $p$ in $v$.
Examples with $v = $ 0b1011 = 11
For $p = 0$ and $w = 1$, $f(11, 0, 1) = 1$
$f(11, p=1, w=1) = 1$
$f(11, p=0, w=2) = 3 = $ 0b11
$f(11, p=1, w=2) = 1 = $ 0b01
etc. (sorry for abusive notations).
this post partially answer by returning a given bit, but I also need the bit-width ads parameter.
(v>>(p+w))is the number after the range that you want. Then(v>>(p+w))<<(p+w)is that padded with zeros on the right. You can subtractv - (v>>(p+w))<<(p+w)to remove the first chunk from the left that is not needed. Finally, remove the chunk from the right(v - (v>>(p+w))<<(p+w))>>p. – plop Aug 23 '22 at 14:03