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

convert byte array to decimal number

Status
Not open for further replies.

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
 
and.... where exactly does you conversion takes place?

------------------
When you do it, do it right.
 
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 []'
 
I'd have used a union:

union
{
char[4] byteval;
short[2] shortval;
float floatval;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top