All pastes #248303 Raw Edit

Mine

public text v1 · immutable
#248303 ·published 2006-11-14 14:50 UTC
rendered paste body

/* lalala chocolate lala
Convert decimal to binary */

#include <stdio.h>

void dtob(int);

int narray[] = { 1, 2, 4, 8, 16, 32, 64, 128 };

void dtob(int n) {
	int x, y, s, tmp;

	for(s = 7; s >= 0; s--) {
		tmp = n / narray[s];
		n = (n) - (tmp * (narray[s]));
		printf("%d", tmp);
	}
	printf("\n");
}

int main () {
	int l = 0;
	printf("( -1 to quit )\n");
	while (1) {
		printf(">> ");
		scanf("%d", &l);
		
		if (l == -1) break;
		if ((l < 256) && (l >= 0))
			dtob(l);
		else
			printf("Entry but be a digit between 0 and 255\n");
	}

	return 0;
}