Sep 20, 2006 #1 paul51 Programmer May 19, 2000 38 US I am trying to convert a byte array to a decimal. The VC++ .net code is: BYTE OUT_VAL_1[4]; OUT_VAL_1[0]=0xBB; OUT_VAL_1[1]=0xD3; OUT_VAL_1[2]=0x01; OUT_VAL_1[3]=0x3F; //made many attempts, with no luck. //the expected conversion is .507137 Thanks
I am trying to convert a byte array to a decimal. The VC++ .net code is: BYTE OUT_VAL_1[4]; OUT_VAL_1[0]=0xBB; OUT_VAL_1[1]=0xD3; OUT_VAL_1[2]=0x01; OUT_VAL_1[3]=0x3F; //made many attempts, with no luck. //the expected conversion is .507137 Thanks
Sep 20, 2006 #2 dEVooXiAm Programmer Jun 8, 2005 103 LT and.... where exactly does you conversion takes place? ------------------ When you do it, do it right. Upvote 0 Downvote
and.... where exactly does you conversion takes place? ------------------ When you do it, do it right.
Sep 20, 2006 Thread starter #3 paul51 Programmer May 19, 2000 38 US My conversion attempts did not work. I tried many things and deleted them. The latest is: unsigned char OUT_VAL_1[] = __gc new unsigned char[4]; //BYTE OUT_VAL_1[4]; OUT_VAL_1[0]=0xBB; OUT_VAL_1[1]=0xD3; OUT_VAL_1[2]=0x01; OUT_VAL_1[3]=0x3F; float A=99; A=BitConverter::ToSingle(OUT_VAL_1,0); error C2440: 'initializing' : cannot convert from 'unsigned char *' to 'unsigned char []' Upvote 0 Downvote
My conversion attempts did not work. I tried many things and deleted them. The latest is: unsigned char OUT_VAL_1[] = __gc new unsigned char[4]; //BYTE OUT_VAL_1[4]; OUT_VAL_1[0]=0xBB; OUT_VAL_1[1]=0xD3; OUT_VAL_1[2]=0x01; OUT_VAL_1[3]=0x3F; float A=99; A=BitConverter::ToSingle(OUT_VAL_1,0); error C2440: 'initializing' : cannot convert from 'unsigned char *' to 'unsigned char []'
Sep 20, 2006 #4 Miros Programmer Jan 27, 2001 506 US I'd have used a union: union { char[4] byteval; short[2] shortval; float floatval; } Upvote 0 Downvote