summaryrefslogtreecommitdiff
path: root/binary.h
diff options
context:
space:
mode:
Diffstat (limited to 'binary.h')
-rw-r--r--binary.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/binary.h b/binary.h
index 2721e9b..cb8bb36 100644
--- a/binary.h
+++ b/binary.h
@@ -45,9 +45,9 @@ static char *binstr(size_t n, char s[n], uintmax_t b)
{
memset(s, '0', n);
s[n - 1] = '\0';
- for (size_t i = 0; i < n && i < BIT_UINTMAXBITS; i++) {
- if (b & (1 << i)) {
- s[n - (i + 1)] = '1';
+ for (size_t i = 0; i < n - 2 && i < BIT_UINTMAXBITS; i++) {
+ if (b & ((uintmax_t)1 << i)) {
+ s[n - (i + 2)] = '1';
}
}
return s;