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!

converting a array of bytes to CString 1

Status
Not open for further replies.

ugly

Programmer
Jul 5, 2002
70
0
0
GB
I want to convert a array of bytes to a string the size of the array can vary but as a example--


CString hold;
byte myArray[3];

myArray[0] = 2;
myArray[1] = 4;
myArray[2] = 8;

i would like hold to be "248"



i would welcome any help on how to do this
thanks martin

ps--also can anyone also explain the difference between data types "byte" and "BYTE"
 
try this:

CString hold;
byte myArray[3];

myArray[0] = 2;
myArray[1] = 4;
myArray[2] = 8;

CString array0, array1, array2;
array0.Format("%d", myArray[0]);
array1.Format("%d", myArray[1]);
array2.Format("%d", myArray[2]);

hold = array0 + array1 + array2;

, you can also use sprinf, if you don't want to create that many CString objects, the problem is that CString's Format function member doesn't work well with more than one parameter, and you can try also multiply first 2*100, 4*10, etc,

Hope this helps,

Ricardo

P.S. : Byte is an 8 bit-integer, i really don't see any difference between the lowercase and the uppercase ones, probably the uppercase one is to maintain compatibility with the MASM data type
 
many many thanks Ricardo for your help
martin
 
How about -

CString hold;
byte myArray[3];

hold=(CString) myArray;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top