summaryrefslogtreecommitdiff
path: root/2/3_int_arith/242.c
blob: 07634e3b6b14d60b14bc47359f2791d9ace310f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>

int div16(int x) {
    // my inefficient method that just checks the sign bit: int sign_bit = (unsigned) (x & 1<<31) >> 31;
    int bias = (x >> 31) & 0xF;
    return (x + bias)>>4;
}

void main() {
    int result = div16(-17);
    printf("%d\n", result);
    result = div16(17);
    printf("%d\n", result);
}