473,385 Members | 1,930 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,385 software developers and data experts.

Converting byte data to hexadecimal ascii

Hi everyone,

I need to convert data from a structure into hexadecimal ascii format.

The structure is like this:

struct ROOM_DATA {
short room_number;
short floor_number;
long total_area;
char comment[42];
};

The structure has different data types so they would occupy different
number of bytes.

The question is if there is a way this data can be printed out in
hexadecimal ascii format?

I'm not sure if there are already functions in C which can do this or
I have to write one myself.

Thanks for any help given.
Nov 14 '05 #1
2 3974
On 12 Apr 2004 22:49:02 -0700, mi*******@lycos.com (Mike Jeffers)
wrote in comp.lang.c:
Hi everyone,

I need to convert data from a structure into hexadecimal ascii format.

The structure is like this:

struct ROOM_DATA {
short room_number;
short floor_number;
long total_area;
char comment[42];
};

The structure has different data types so they would occupy different
number of bytes.

The question is if there is a way this data can be printed out in
hexadecimal ascii format?

I'm not sure if there are already functions in C which can do this or
I have to write one myself.

Thanks for any help given.


Consult your C book for the "%x" conversion specifier of the printf()
function. It does hexadecimal quite well. It even does it in ASCII,
if that is the execution character set of your implementation. Which
is quite likely.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #2
On 12 Apr 2004 22:49:02 -0700, mi*******@lycos.com (Mike Jeffers) wrote:
I need to convert data from a structure into hexadecimal ascii format.

The structure is like this:

struct ROOM_DATA {
short room_number;
short floor_number;
long total_area;
char comment[42];
};

The structure has different data types so they would occupy different
number of bytes.

The question is if there is a way this data can be printed out in
hexadecimal ascii format?


There is no built-in function in C to do this, but you can easily write one
yourself.

Here's a proposed declaration:

void dumpobj(const void *object, size_t objsize);

This function could be used to dump the contents of any arbitrarily-sized
data type.

In dumpobj, simply walk through the object in a character-by-character
fashion, displaying each character as a hex number. You can get as fancy
as you wish--display the data as both hex and ASCII characters, justify the
dump in x-byte paragraphs, etc.
--
Robert B. Clark (email ROT13'ed)
Visit ClarkWehyr Enterprises On-Line at http://www.3clarks.com/ClarkWehyr/
Nov 14 '05 #3

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

Similar topics

1
by: Mike Jeffers | last post by:
Hi everyone, I need to convert data from a structure into hexadecimal ascii format. The structure is like this: struct ROOM_DATA { short room_number; short floor_number; long total_area;
4
by: Luk Vloemans | last post by:
Hey, I'm currently working on a project to get GPS-data onto a PDA. At this stage, I'm already getting data from the device, but my problem is: It's rubbish. At least, it looks as if it were...
4
by: Prabhu | last post by:
Hi, We are having problem in converting a byte array to string, The byte array has char(174), char(175), char(240), char(242) and char(247) as delimiters for the message. when we use...
5
by: scott | last post by:
hi all, hope some one can help me, this prob is driving me mad. im using sockets to communicate between a client and a server. I don't' have control over the client and how it sends the data...
8
by: moondaddy | last post by:
I need to convert a byte array to a string and pass it as a parameter in a URL and then convert it back to the original byte array. However, its getting scrambled in the conversion. In short,...
6
by: LCD | last post by:
This a rather simple question for all you studs out there! Please help me with this. I have a string = "Please help me", and I want to convert this into it's hex equivalent. How do I do it, I...
5
by: Jeff Dillon | last post by:
How might I convert a string like 10.A (in hex) to it's decimal equivalent? Basically I have an input string like ((1F.A + 3A.D) - 1F.E) and need to calculate the result. Using Reflection and...
2
by: DBuss | last post by:
OK, I'm reading a multicast socket. It attaches fine, reads fine, all of that. The problem is that while some of the data I get is normal text (ASCII String), some of it is Binary Integer. ...
9
by: Jeremy Kitchen | last post by:
Are there any library functions that can help me to do this? If necessary I can convert the string to a byte array. I don't want to have to write my own Hex conversion if it isn't necessary. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.