cosmopolitan/tool/decode/word.c
Justine Tunney a6baba1b07
Stop using .com extension in monorepo
The WIN32 CreateProcess() function does not require an .exe or .com
suffix in order to spawn an executable. Now that we have Cosmo bash
we're no longer so dependent on the cmd.exe prompt.
2024-03-03 03:12:19 -08:00

29 lines
606 B
C

#include "libc/assert.h"
#include "libc/fmt/conv.h"
#include "libc/stdio/stdio.h"
/**
* Displays bytes as word, e.g.
*
* o//tool/word 6e c7 ff ff
* %d = -14482
* %ld = 4294952814
* %#x = 0xffffc76e
* %#lx = 0xffffc76e
*
*/
int main(int argc, char *argv[]) {
long x;
int i, k, b;
for (x = k = 0, i = 1; i < argc; ++i) {
b = strtol(argv[i], 0, 16);
assert(0 <= b && b <= 255);
x |= (unsigned long)b << k;
k += 8;
}
printf("%%d = %d\n"
"%%ld = %ld\n"
"%%#x = %#x\n"
"%%#lx = %#lx\n",
(int)x, x, (int)x, x);
}