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

ASCII to HEX

char string[] = "1d,4c,20,00";
char target[] = {0x1d,0x4c,0x20,0x00};
char buf[64];

I have searched newgroups and am actively searching online for a
function to take the value of string and place it into buf so that buf
== target.

Any ideas would be greatly appreciated,
Tyler Kellen
Nov 14 '05 #1
3 4664

Tyler Kellen wrote:
char string[] = "1d,4c,20,00";
char target[] = {0x1d,0x4c,0x20,0x00};
char buf[64];

I have searched newgroups and am actively searching online for a
function to take the value of string and place it into buf so that buf
== target.


Sounds quite like homework for me.
Give us your code or ideas and we will help you improve it/
find errors or possible sources of errors.

Functions which may help you writing the code:
strtoul(), sscanf(). For general separator handling, use a
string (e.g. char separators[]=",; ") and strchr() when parsing
string.
Or do it by hand, extracting the hex digits of one number
and converting it yourself.
Note: Hex expressions usually denote nonnegative numbers,
so
unsigned char target[] = {0x1d,0x4c,0x20,0x00};
unsigned char buf[64];
may be more appropriate.
Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #2
"Tyler Kellen" <ty***@stardotbox.com> wrote in message
news:64*************************@posting.google.co m...
char string[] = "1d,4c,20,00";
char target[] = {0x1d,0x4c,0x20,0x00};
char buf[64];

I have searched newgroups and am actively searching online for a
function to take the value of string and place it into buf so that buf
== target.


Don't search online, look in a C book. The C standard library
contains two functions which will convert text to a numeric
value, in various number bases, including hexadecimal.
Look up 'sscanf()' and 'strtoul()'.

-Mike

Nov 14 '05 #3
ty***@stardotbox.com (Tyler Kellen) wrote:
# char string[] = "1d,4c,20,00";
# char target[] = {0x1d,0x4c,0x20,0x00};
# char buf[64];

You can convert the prefix of a string which is a hex number without a leading
'0x' by code = strtol(string,&lba,16). chars are already integers, so you can
just assign the output of strtol to the char variable. If the assigned value
is outside the range representable by the char, it is silently truncated.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
If your job was as meaningless as theirs, wouldn't you go crazy too?
Nov 14 '05 #4

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

Similar topics

37
by: chandy | last post by:
Hi, I have an Html document that declares that it uses the utf-8 character set. As this document is editable via a web interface I need to make sure than high-ascii characters that may be...
4
by: wob | last post by:
Many thanks for those who responded to my question of "putting greek char into C string". In searching for an solution, I noticed that there are more than one version of "Extended ASCII...
2
by: Martín Marconcini | last post by:
Hello there, I'm writting (or trying to) a Console Application in C#. I has to be console. I remember back in the old days of Cobol (Unisys), Clipper and even Basic, I used to use a program...
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
31
by: Claude Yih | last post by:
Hi, everyone. I got a question. How can I identify whether a file is a binary file or an ascii text file? For instance, I wrote a piece of code and saved as "Test.c". I knew it was an ascii text...
24
by: ChaosKCW | last post by:
Hi I am reading from an oracle database using cx_Oracle. I am writing to a SQLite database using apsw. The oracle database is returning utf-8 characters for euopean item names, ie special...
7
by: Jeffrey Spoon | last post by:
Hello, I'm a bit stuck trying to convert a text file which contains extended ASCII text and changing the ASCII values so they become readable. I do this by subtracting 127 from the ASCII value....
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
4
by: meendar | last post by:
Hi, I am having a character pointer which contains ascii values. i just want to convert all these ascii values to respective characters and again store it in another character pointer. ...
9
by: =?Utf-8?B?RGFu?= | last post by:
I have the following code section that I thought would strip out all the non-ascii characters from a string after decoding it. Unfortunately the non-ascii characters are still in the string....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.