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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conversion problem

Status
Not open for further replies.

zaphy2k2

Programmer
Dec 23, 2001
30
GB
Hi,

I get a series of UCHARs from a function, 0s and 1s, and need to put them into a string eg "10010110011", which i can then convert to an unsigned long, but i can't get the UCHARs to store in an array or concat onto a string. Could someone please point me in the right direction? (C++ newbie-ish)

cheers
aaron
 

UCHAR newChar;

// I dont know how they are coming over but this will
// handle both situations


char buffer[128];
*buffer = 0;

// some loop to get the uchars
UCHAR c = GetUCHAR();

strcat(buffer,( c==0 || c=='0' ? "0":"1"));

// end of loop

char* endPtr;
ULONG value = strtol(buffer,endPtr,2);

cout<<value;


Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top