hello sirs. im trying to turn two 8-bit hex characters that represent the lsb and msb of an integer. below is the code i am using. i am getting output though im not sure of the validity.

char a = 0x01;   //msb
char b = 0x3D;   //lsb
short int d;

d = ((short int) (a << 8)) | b;

is this the way to go or is there a more efficient way to ensure avoiding the loss of data?
thanks

Recommended Answers

All 3 Replies

Output d as a hex value, or use a decimal-hex calculator to check the answer.

thanks! regarding my casting to short int of the two chars, that acceptable programming practice right?

What you did is perfectly acceptable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.