1. 程式人生 > >C語言:以二進位制方式列印資料

C語言:以二進位制方式列印資料

程式碼:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void decToBin(int num)
{
	if(num>0)
		{
			decToBin(num/2);
			printf("%d",num%2);
		}
}

int main()
{
	int num = 1234567891;
	decToBin(num);
	printf("\n");
	return 0;
}

執行結果:

[email protected]:/mnt/hgfs/Ubuntu12.04-share# ./test
1001001100101100000001011010011
[email protected]
:/mnt/hgfs/Ubuntu12.04-share#

參考連結:
https://blog.csdn.net/xzongyuan/article/details/28889063