十进制转为任意位数的二进制

void func( unsigned int num, unsigned int nbit, char *str )
{
	unsigned int	i;
	unsigned int	j = 0;
	for ( i = nbit - 1; i >= 0; i-- )
	{
		str[j++] = '0' + ( (num >> i) & 1);
	}
}

你可能感兴趣的:(随笔,基础,C语言,算法,十进制,二进制)