473,587 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4007
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.l earn.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
474
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
2273
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 rubbish. example: "`?~?\0?~?~????\0x?x?x?x?x?x~??x?x?xx?\0x?x?" I found patterns in the code I received, so it's just encoded.
4
5377
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 "System.Text.Encoding.ASCII.GetString(bytearray)" of .Net library, we found that the char (delimiters) specified above are replaced with different char.
5
1481
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 so i have had to try and work out how it is doing it. From what i can see it is sending the data in ASCII because if i try to use Unicode it just...
8
4190
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, here's the code: ====================================== Dim textConverter As New ASCIIEncoding Dim sParam As String = "This is my cool param" Dim...
6
43163
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 have trying for a couple hours and can't seem to get my head straight arount this whole conversion things. TIA, LCD
5
5574
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 dynamic compilation, I was able to create a VB.NET equivalent of the older Eval function, but it only works with decimal numbers. Any thoughts? I know...
2
4356
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. The binary data is how they send numbers (they call it "Big Endian"). I only know at run time whether a byte is going to be text or binary (one of the...
9
9721
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. Thanks for any help Jeremy Kitchen
0
7918
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8206
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5713
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.