Binary to string convert
I copied two methods in these site:
http://devpinoy.org/forums/t/1339.aspx and
http://www.codeguru.com/forum/archive/index.php/t-323807.html
I worked assembling in two site's methods.
Codes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <iostream>
#include <fstream>
#include <windows.h>
#include <tchar.h>
#ifdef _UNICODE
#define tstring wstring
#define tcout wcout
#else
#define tstring string
#define tcout cout
#endif
using namespace std;
int ConvertBinaryToInteger(BYTE *byteToConvert, int intSize)
{
int intNumber = 0;
for(int i=0; i<intSize-1; i++)
{
int tmpNum = 0;
if(byteToConvert[i] == 1)
{
tmpNum = 1;
for(int j=0; j<((intSize-1)-i); j++)
tmpNum *= 2; //lets do calculation manually
}
intNumber += tmpNum;
}
intNumber += (byteToConvert[intSize-1] == 1)?1:0; //add the last bit
return intNumber;
}
char ConvertBinaryToChar(BYTE *byteToConvert, int intSize)
{
return (char)ConvertBinaryToInteger(byteToConvert, intSize);
}
tstring cevirme(tstring ikili){
LPCTSTR ikiliWin=ikili.c_str();
string cumle="";
if((ikili.length()%8)!=0)
return "";
for(int i=0;i<ikili.length();i++){
BYTE ikilidegerler[8];
for(int j=0;j<8;j++){
ikilidegerler[j]=1;
if(ikiliWin.At(i++)=='0')
ikilidegerler[j]=0;
}
cumle+=ConvertBinaryToChar(ikilidegerler, 8);
}
return cumle;
}
int main(){
tstring a;
fstream dosya;
dosya.open("ikiligirisx6.txt");
dosya>>a;
cout<<cevirme(a);
return 0;}
|
At or GetAt func didn't work.May be another funcs doesn't work.
Last edited on
Topic archived. No new replies allowed.