Algorithm for copying N bits at arbitrary position from one int to another

前端 未结 7 1774
别那么骄傲
别那么骄傲 2021-01-31 21:36

An interesting problem I\'ve been pondering the past few days is how to copy one integer\'s bits into another integer at a given position in the destination integer. So, for exa

7条回答
  •  梦如初夏
    2021-01-31 22:13

    Generalized GRB-fnieto form...

    template 
    T setbits4(T destination, T source, int at, int numbits)
    {
        T mask = (((T)-1)>>(sizeof(T)*8-numbits))<

提交回复
热议问题