The method of using the bit realizes the conversion of the credit (smart and light)

xiaoxiao2021-03-06  172

#include #include #include #include // Put n with binary series to STRCHAR * DTOB (Char * STR, UNSIGNED Long N) { INT i; unsigned long m = 0x80000000; for (i = 0; i <32; i) {STR [I] = (m & n)? '1': '0'; m >> = 1;} STR [32] = '/ 0'; return str;} // From the binary string read number unsigned long btod (int i; unsigned long m; unsigned long n = 0; int LEN = Strlen (STR) ; If (len> 32) len = 32; m = 0x80000000 >> (32 - LEN); for (i = 0; i > = 1;} return n;} void main () {char STR [32]; cout << btod ("1010101001") << endl; cout << DTOB (STR, 12211111111111) << endl;}

转载请注明原文地址:https://www.9cbs.com/read-128541.html

New Post(0)