shift-left

xod/bits/shift-left

Performs logical left-shift of `IN` by `N` bits.
shift-left
@/shift-left
Performs logical left-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-left
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
115-2115
32.55032
-239523.230-239523
124
12842048
-10243-8192
-10243.5-8192
131-2147483648
1254-2147483648
1260-2147483648
1000000000310
10000000002500
-1000000000310
-10000000002500