?? 00.cpp
字號:
#include"memory.h"
#include <stdio.h>
#include<string>
#include<iostream>
using namespace std;
//unsigned long string_to_long(const char* code)
unsigned long string_to_long(string str)
{
const char*code=str.c_str();
unsigned long ret = 0;
int len = (int)strlen(code);
for(int i = len - 1; i >= 0; i--)
if (code[i] == '1')
ret |= (1ul << (len - i - 1));
return ret;
}
string long_to_string(unsigned long code, int code_len)
{
char* buf = new char[code_len + 1];
if (buf == NULL)
cout<<"no enough memory."<<endl;
memset(buf, 0, code_len + 1);
unsigned long bit = 1 << (code_len - 1);
for(int i = 0; i < code_len; i++)
{
if (code & bit)
buf[i] = '1';
else
buf[i] = '0';
bit >>= 1;
}
string ret(buf);
delete buf;
return ret;
}
void main()
{
//char code[9]="10011010";
string code="10011010";
unsigned long key=string_to_long(code);
cout<<key<<endl;
char ch=char(key);
char store[8],temp;
for ( int i = 0 ; i < 8 ; i++ )
{
if ( ch & 128 ){ temp = '1'; }
else { temp = '0'; }
ch = ch << 1;
store [ i ] = temp;
}
string k=store;
cout<<k<<endl;
//cout<< long_to_string(key,9);
}
/*
void main()
{
char code[11]="1001101010";
unsigned long key=string_to_long(code);
unsigned t=key;
for(int i=0;i<10;i++)
{ t=t>>1;
cout<<char(t)<<endl;
cout<< long_to_string(t,10)<<endl;
}
}
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -