473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

hexadecimal ( WORD)

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[i])
}

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.
Nov 14 '05 #1
1 2256
you could do something like:

// HOW CAN I get the parameter value in the comm_send below, as
mention in my example below? Any algorithm ?
comm_send((char)(checksum / 256))
comm_send((char)(checksum % 256))
modding it by 256 will give you the LSB,
you can always try the shift operator, which is >> or <<.

// 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.

Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Paul | last post by:
Hi, (First apologies if this is not the most relevant place to post this but I wasn't sure of where was and I am writing my app in VB.) I'm attempting to parse a binary file for which I have...
0
by: thomasp | last post by:
I have not had any luck with this on other groups so I am posting it here. I created a .rtf file using MS Word that included text and graphics(.png file) . I then viewed this file with notepad. ...
3
by: Todd | last post by:
Our ASP.NET (C#) application accepts form entry and saves inputed data in XML. We are finding that users are sometimes cutting and pasting special characters (from MS Word) into these forms....
1
by: Fernando Barsoba | last post by:
Hi all, First of all, I'd like to thank you "Skarmander" and "Flash Gordon" for the help they provided me: Skarmander's algorithm and Flash's modifications helped me a lot. Here's the problem...
7
by: onetitfemme | last post by:
Hi, for some reason Firefox is apparently inserting a new line somehow after some IPA symbols which I have written in their hexadecimal notation. Also, I would like to have two spaces by...
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
8
by: Vijay | last post by:
Hi , I am doing a small project in c. I have a Hexadecimal file and want to convert into ascii value. (i.e., Hexadecimal to Ascii conversion from a file). Could anyone help me? Thanks in...
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
6
by: Andrea | last post by:
Hi, suppose that I have a string that is an hexadecimal number, in order to print this string I have to do: void print_hex(unsigned char *bs, unsigned int n){ int i; for (i=0;i<n;i++){...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.