1

intを1つ右にシフトして、戻す必要があります

Javaでは、n>>1を返すことができます。

これはCで可能ですか?

与えられた方法は次のとおりです

// Return n after a right circular 1-bit shift
unsigned int right_circular_shift_1(unsigned int n) {
4

2 に答える 2

10

C には巡回シフトがないので、演習はそれを実装することだと思います。左循環シフトに対してこれを行う方法は次のとおりです。

- get the current leftmost bit  and save it
- shift the number leftwards by one
- or the saved bit in at the rightmost bit position

右循環シフトの場合:

- get the current rightmost bit  and save it
- shift the number rightwards by one
- or the saved bit in at the leftmost bit position
于 2010-05-31T11:47:24.927 に答える
5

試したことはありませんか?

n >> 1

これは、C (およびその他の C ベースの言語) でも Java と同様に機能します (ただし循環ではありません)。

于 2010-05-31T11:47:52.867 に答える