Bitwise shifting array of char's

后端 未结 7 1583
谎友^
谎友^ 2020-12-03 17:41

I have got an array of chars that I\'m trying to bitwise shift right >>, then & with another array. I think I have got the wrong idea of

相关标签:
7条回答
  • 2020-12-03 18:38

    You'll have to shift the entries in the array one by one. (And if you want to compare two of these, you'll need to do it element by element.)

    If you were hoping that bits shifted off each char would get shifted into the next one, you'll need to take care of that manually too.

    If you are wanting that shift-into-the-next-byte behaviour, and don't mind making your code nasty and nonportable and bug-prone, you might be able to take a pointer to the array, cast it to something like unsigned long long *, dereference it and shift the resulting integer, and store it back again.

    BUT if that's the behaviour you want then you should be using an integer instead of a char[8] to begin with.

    (If you could say more about what you're actually aiming to achieve, then more helpful answers may be possible.)

    0 讨论(0)
提交回复
热议问题