M
Magix
Hi,
I have following question in hex, regarding converting Dec(which is greater
than 255, to hex ( 2 bytes/ WORD). How can I convert and put the total
checksum of a string, and put it in hex char format. See below example.
Let say I have these function.
comm_send(char p) // transmit a character via serial port
{
....
}
void func1(char *str)
{
// I would like to calculate the checksum in WORD (2 byte)
for (i=0; i<strlen(str);i++)
{
checksum = checksum+char_to_dec(str)
}
if (checksum<= 255)
{
comm_send(0x00);
comm_send((char)checksum));
}
else // checksum is > 255
{
// HOW CAN I get the parameter value in the comm_send below, as
mention in my example below? Any algorithm ?
comm_send(...)
comm_send(...)
// example: if the checksum is 500 in decimal, in hex value
// it will be 1F4, I would like to
// show it as 0x01 (MSB) and 0xF4 (LSB), which will be
// comm_send(0x01);
// comm_send(0xF4);
}
}
Is there any built in function to convert decimal to hex ? If using HIBYTE
and LOBYTE Macros, how to apply them ?
Thanks.
I have following question in hex, regarding converting Dec(which is greater
than 255, to hex ( 2 bytes/ WORD). How can I convert and put the total
checksum of a string, and put it in hex char format. See below example.
Let say I have these function.
comm_send(char p) // transmit a character via serial port
{
....
}
void func1(char *str)
{
// I would like to calculate the checksum in WORD (2 byte)
for (i=0; i<strlen(str);i++)
{
checksum = checksum+char_to_dec(str)
}
if (checksum<= 255)
{
comm_send(0x00);
comm_send((char)checksum));
}
else // checksum is > 255
{
// HOW CAN I get the parameter value in the comm_send below, as
mention in my example below? Any algorithm ?
comm_send(...)
comm_send(...)
// example: if the checksum is 500 in decimal, in hex value
// it will be 1F4, I would like to
// show it as 0x01 (MSB) and 0xF4 (LSB), which will be
// comm_send(0x01);
// comm_send(0xF4);
}
}
Is there any built in function to convert decimal to hex ? If using HIBYTE
and LOBYTE Macros, how to apply them ?
Thanks.