All pastes #96673 Raw Edit

Someone

public text v1 · immutable
#96673 ·published 2006-07-23 02:18 UTC
rendered paste body
#include <stdlib.h>
#include <stdio.h>

const int BITS_PER_INT = 8 * sizeof(int);

int main(int argc, char* argv[])
{
    --argc; ++argv;
    
    if (argc == 0)
    {
        printf("Specify at least one argument.\n");
        return 1;
    }
    
    for (int i = 0; i < argc; ++i)
    {
        int temp = atoi(argv[i]);
        char str[BITS_PER_INT + 1];
        str[BITS_PER_INT] = '\0';
        
        for (int i = BITS_PER_INT - 1; i >= 0; --i)
        //for (int i = 0; i < BITS_PER_INT; ++i)
        {
            str[i] = (temp & (1 << i)) ? '1' : '0';
            printf(" * i = %d, str[i] = %c\n", i, str[i]);
        }
        
        printf("%d = 0b%s\n", temp, str);
    }
}