/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>

void binary_print_fixed(int value, int width)
{
    int i, temp;
    char buffer[33];
    temp = value;
    for(i = width - 1; i >= 0; i--)
    {
        buffer[i] = '0' + temp % 2;
        temp /= 2;
    }
    buffer[width] = '\0';
    printf("%s\n", buffer);
}

void binary_print(int value)
{
    int temp, digits;
    temp = value;
    digits = 0;
    while(temp > 0)
    {
        digits++;
        temp >>= 1;
    }
    binary_print_fixed(value, digits);
}

int main()
{
    binary_print_fixed(125, 8);
    binary_print(125);
    return 0;
}
