0

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

Edited by iwanttolearnc: n/a

2
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by WaltP
1

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

0

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

Edited by iwanttolearnc: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.