C言語の進数変換
/* :
: 0b;
: 0;
: 0x;
;
: printf %o ;
: printf %x ;
C , ;
: printf %i %d ;
: m , nk,nk-1,nk-2,...,n2,n1,n0 l
m = n0 + n1 * l^1 + n2 * l^2 + .... + nk-2 * l^(k-2) + nk-1 * l ^(k-1) + nk * l^k
, l , n0, l n1, , m l
: ( )
#include
void printBin(int num);
int main(int argc, const char * argv[]) {
int num = 4; // 100;
printBin(num);
return 0;
}
void printBin(int num)
{
int zheng = num;
while (zheng != 0)
{
int yu = zheng % 2;
printf("%i",yu);
zheng = zheng / 2;
}
printf("
");
}
n : 0~2^n -1
:
:
, , , ,
: ( 0, 1),
: , ,
: , 1
:
: & # , , , , 1 # :
: | # , , , , 0
: ^ # , , 0, 1. 0, # :
: ^ # , , , ,
: <> # n , , 2^n
# :
:
:
int num1 = 32;
int num2 = 21;
int temp = num1 + num2;
num1 = temp - num1;
num2 = temp - num1;
:
int num1 = 32;
int num2 = 21;
int temp = num1 ^ num2;
num1 = temp ^ num1;
num2 = temp ^ num1;
: :
( , ) :
void printBin(int num);
int num = 3;
printBin(num);
void printBin(int num)
{
int delta = 31;
for (int i = delta;i >= 0;i--)
{
int result = (num >> i) & 1;
printf("%i",result);
if (i % 4 == 0)
{
printf(" ");
}
}
printf("
");
}
( ) :
void printBin(int num);
int num = 3;
printBin(num);
void printBin(int num)
{
int delta = 0;
for(int i = delta;i > i) & 1;
printf("%i",result);
}
printf("
");
}
# : , 0
( ) :
void printBin(int num);
int num = -4;
printBin(num);
void printBin(int num)
{
int count = 0 ;
while((num >> count) != 0)
{
int result = (num >> count) & 1;
printf("%i",result);
count++;
}
printf("
");
}
*/