Commit b58242c5 authored by Chen Bill's avatar Chen Bill

update bit.extract, bit.replace

parent 7c918ad9
......@@ -37,10 +37,12 @@ local function fieldargs(f,width)
return f,~(-1<<w)
end
function bit.extract(r,field,width)
width=width or 1
local f,m=fieldargs(field,width)
return (r>>f)&m
end
function bit.replace(r,v,field,width)
width=width or 1
local f,m=fieldargs(field,width)
return (r&~(m<<f))|((v&m)<< f)
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment