better shifting

This commit is contained in:
Christoph J. Scherr 2023-04-25 11:15:48 +02:00
parent c82d9414ca
commit 867f7c87af
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
1 changed files with 15 additions and 7 deletions

View File

@ -26,11 +26,19 @@ uint32_t rotr32 (uint32_t value, unsigned int count) {
return (value >> count) | (value << (-count & mask));
}
uint32_t main() {
uint32_t x = 0x1337;
uint32_t rotr = rotr32(x, 17);
uint32_t rotl = rotl32(x, 17);
printf("original:\t%032b - 0x%x - %d\n", x, x, x, x);
printf("rshifted:\t%032b - 0x%x - %d\n", x, rotr, rotr, rotr);
printf("lshifted:\t%032b - 0x%x - %d\n", x, rotl, rotl, rotl);
uint32_t main(int* argc, char** argv) {
if (argc < 3) {
printf("give two integers as argument!\n");
return 1;
}
uint32_t x;
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);
}