better shifting
This commit is contained in:
parent
c82d9414ca
commit
867f7c87af
|
@ -26,11 +26,19 @@ uint32_t rotr32 (uint32_t value, unsigned int count) {
|
||||||
return (value >> count) | (value << (-count & mask));
|
return (value >> count) | (value << (-count & mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t main() {
|
uint32_t main(int* argc, char** argv) {
|
||||||
uint32_t x = 0x1337;
|
if (argc < 3) {
|
||||||
uint32_t rotr = rotr32(x, 17);
|
printf("give two integers as argument!\n");
|
||||||
uint32_t rotl = rotl32(x, 17);
|
return 1;
|
||||||
printf("original:\t%032b - 0x%x - %d\n", x, x, x, x);
|
}
|
||||||
printf("rshifted:\t%032b - 0x%x - %d\n", x, rotr, rotr, rotr);
|
uint32_t x;
|
||||||
printf("lshifted:\t%032b - 0x%x - %d\n", x, rotl, rotl, rotl);
|
uint32_t shift_width;
|
||||||
|
sscanf(argv[1], "%d", &x);
|
||||||
|
sscanf(argv[2], "%d", &shift_width);
|
||||||
|
printf("shift width:\t%d\n", shift_width);
|
||||||
|
uint32_t rotr = rotr32(x, shift_width);
|
||||||
|
uint32_t rotl = rotl32(x, shift_width);
|
||||||
|
printf("original: 0b%032b | 0x%08x | %u\n", x, x, x, x);
|
||||||
|
printf("rshifted: 0b%032b | 0x%08x | %u\n", rotr, rotr, rotr, rotr);
|
||||||
|
printf("lshifted: 0b%032b | 0x%08x | %u\n", rotl, rotl, rotl, rotl);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue