Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Binary to Char

Status
Not open for further replies.

hou

IS-IT--Management
Jan 29, 2003
4
0
0
CA
Hi

My question is maybe trivial for some P :) if (true) just help plz ;-)

I am using BCB 6, I would like to convert the binary value of an ascii value of char to get char it self.

exple :
toascii to bin
h -----> 104 (dec) ------> 1101000

I need to do the reverse...
Is there any c++ function to do that (something like itoa,itol..) . If not how to do that?

Any input on this matter would be very much appreciated.

Thx in advance..

Hou

 
I know of no such function but write it yourself!
I take the conversion is from ASCII datas to a int.

int Bin2Int(char * Source, int Length)
{
int Result = 0;
while(Length && ((*Source == '0') || (*Source == '1'))
{
Result <<= 1; // Shift left once
Result += *(Source++) - '0';
Length--;
}
return(Result);
}

Totte
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top