转换2进制代码

void FormatBinary(__int64 num,char buf[])

{

    int nCount = 0 ;



    while ( 1 )

    {

        if( ( (__int64) 1 << nCount ) > num)

            break ;



        if( ( num >> nCount ) & 1 == 1)

        {

            buf[nCount] = '1';

        }else

        {

            buf[nCount] = '0' ;

        }

        nCount++;



    }

    for (int i = 0 ; i < nCount / 2 ; i++)

    {

        char temp = buf[i];

        buf[i] = buf[nCount-i-1];

        buf[nCount-i] = temp ;

    }

}

 

你可能感兴趣的:(代码)