c get nth byte of integer

前端 未结 4 665
长情又很酷
长情又很酷 2020-11-28 06:01

I know you can get the first byte by using

int x = number & ((1<<8)-1);

or

int x = number & 0xFF;

4条回答
  •  隐瞒了意图╮
    2020-11-28 06:24

    int nth = (number >> (n * 8)) & 0xFF;

    Carry it into the lowest byte and take it in the "familiar" manner.

提交回复
热议问题