Skip to content

Instantly share code, notes, and snippets.

@pdp7
Created November 22, 2025 16:40
Show Gist options
  • Select an option

  • Save pdp7/fd4ff013297e8ba54c1d56533e4a1d45 to your computer and use it in GitHub Desktop.

Select an option

Save pdp7/fd4ff013297e8ba54c1d56533e4a1d45 to your computer and use it in GitHub Desktop.
cbqri bitmask width bmw
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
long int_value;
char *endptr;
int x;
if (argc < 2) {
printf("Usage: %s <integer_argument>\n", argv[0]);
return 1; // Indicate an error
}
int_value = strtol(argv[1], &endptr, 0);
if (*endptr != '\0') {
fprintf(stderr, "Error: Invalid integer format for argument '%s'\n", argv[1]);
return 1;
}
printf("Parsed integer: %ld\n", int_value);
x = int_value;
printf("x = %d\n", x);
x = x + 63;
printf("x += 63 => %d\n", x);
x = x / 64;
printf("x /= 64 => %d\n", x);
x = x * 64;
printf("x *= 64 => BMW is %d bits\n", x);
x = x / 8;
printf("x /= 8 => BMW is %d bytes\n", x);
return 0;
}
~
@pdp7
Copy link
Author

pdp7 commented Nov 22, 2025

Usage: ./bmw <integer_argument>
pdp7@x1:~/tmp$ gcc -o bmw bmw.c && ./bmw 256
Parsed integer: 256
x = 256
x += 63 => 319
x /= 64 => 4
x *= 64 => BMW is 256 bits
x /=  8 => BMW is 32 bytes
pdp7@x1:~/tmp$ gcc -o bmw bmw.c && ./bmw 12
Parsed integer: 12
x = 12
x += 63 => 75
x /= 64 => 1
x *= 64 => BMW is 64 bits
x /=  8 => BMW is 8 bytes
pdp7@x1:~/tmp$ gcc -o bmw bmw.c && ./bmw 16
Parsed integer: 16
x = 16
x += 63 => 79
x /= 64 => 1
x *= 64 => BMW is 64 bits
x /=  8 => BMW is 8 bytes
pdp7@x1:~/tmp$ gcc -o bmw bmw.c && ./bmw 32
Parsed integer: 32
x = 32
x += 63 => 95
x /= 64 => 1
x *= 64 => BMW is 64 bits
x /=  8 => BMW is 8 bytes
pdp7@x1:~/tmp$ gcc -o bmw bmw.c && ./bmw 64
Parsed integer: 64
x = 64
x += 63 => 127
x /= 64 => 1
x *= 64 => BMW is 64 bits
x /=  8 => BMW is 8 bytes
pdp7@x1:~/tmp$ gcc -o bmw bmw.c && ./bmw 65
Parsed integer: 65
x = 65
x += 63 => 128
x /= 64 => 2
x *= 64 => BMW is 128 bits
x /=  8 => BMW is 16 bytes
pdp7@x1:~/tmp$ gcc -o bmw bmw.c && ./bmw 90
Parsed integer: 90
x = 90
x += 63 => 153
x /= 64 => 2
x *= 64 => BMW is 128 bits
x /=  8 => BMW is 16 bytes
pdp7@x1:~/tmp$ gcc -o bmw bmw.c && ./bmw 128
Parsed integer: 128
x = 128
x += 63 => 191
x /= 64 => 2
x *= 64 => BMW is 128 bits
x /=  8 => BMW is 16 bytes
pdp7@x1:~/tmp$ gcc -o bmw bmw.c && ./bmw 129
Parsed integer: 129
x = 129
x += 63 => 192
x /= 64 => 3
x *= 64 => BMW is 192 bits
x /=  8 => BMW is 24 bytes
pdp7@x1:~/tmp$ gcc -o bmw bmw.c && ./bmw 140
Parsed integer: 140
x = 140
x += 63 => 203
x /= 64 => 3
x *= 64 => BMW is 192 bits
x /=  8 => BMW is 24 bytes
pdp7@x1:~/tmp$ gcc -o bmw bmw.c && ./bmw 190
Parsed integer: 190
x = 190
x += 63 => 253
x /= 64 => 3
x *= 64 => BMW is 192 bits
x /=  8 => BMW is 24 bytes
pdp7@x1:~/tmp$ gcc -o bmw bmw.c && ./bmw 211
Parsed integer: 211
x = 211
x += 63 => 274
x /= 64 => 4
x *= 64 => BMW is 256 bits
x /=  8 => BMW is 32 bytes
pdp7@x1:~/tmp$ d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment