shift-right

xod/bits/shift-right

Performs logical right-shift of `IN` by `N` bits.
shift-right
@/shift-right
Performs logical right-shift of `IN` by `N` bits.
INnumber
Input number. Interpreted as a signed 32-bit interger
Nnumber
Shift bits count. Truncated to an integer. Negative values round to zero
shift-right
IN
OUT
N
OUTnumber

C++ implementation

#pragma XOD dirtieness disable

node {
    void evaluate(Context ctx) {
        int32_t x = (int32_t)getValue<input_IN>(ctx);
        int32_t n = (int32_t)getValue<input_N>(ctx);
        int32_t b = 0;
        if (n < 0) {
          b = 0;
        } else if (n > 31) {
          b = 31;
        } else {
          b = n;
        }
        emitValue<output_OUT>(ctx, x >> b);
    }
}

Tabular tests

INNOUT
000
101
-10-1
101-52101
32.55032
-239523.230-239523
120
12848
-10243-128
-10243.5-128
1000000000310
1000000000320
10000000002500
-100000000031-1
-100000000032-1
-1000000000250-1