473,847 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question: Unicode <-> HEX conversion in C source file?

^_^
conversion from:

a="a";

to

a=0x????;

If there are many unicode strings to convert, how can I do batch-conversion?
Nov 14 '05 #1
16 11062
^_^ wrote:
conversion from:

a="a";

to

a=0x????;

If there are many unicode strings to convert, how can I do batch-conversion?


If you really want help, then

1) Stop cross-posting wildly.
2) Stop re-posting similar messages over and over.
3) Phrase your question in a way that we can understand it.

Try posting ONE message to ONE relevant group that explains your problem
in sufficient detail, then wait for a reply (which may take several
hours). Otherwise you are likely to be ignored, flamed, and/or killfiled.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #2
> If you really want help, then

1) Stop cross-posting wildly.
2) Stop re-posting similar messages over and over.
3) Phrase your question in a way that we can understand it.

Try posting ONE message to ONE relevant group that explains your problem
in sufficient detail, then wait for a reply (which may take several
hours). Otherwise you are likely to be ignored, flamed, and/or killfiled.


I don't think this guy speaks English that well, it is a foreign language to
him, hence the cryptic messages.
Probably Chinese.

Stephen Howe
Nov 14 '05 #3
Stephen Howe wrote:
I don't think this guy speaks English that well, it is a
foreign language to him, hence the cryptic messages. Probably
Chinese.


[Reading in news:comp.lang. c]

No need to guess. From cleansugar's header:

Organization: Korea Telecom
Message-ID: <bt**********@n ews1.kornet.net >

I think the OP wants a tool that can be used to convert string
literals to unicode equivalents in C and/or C++ source files.

Can someone who knows more about this than I either redirect or
provide help?
--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c
Read my lips: The apple doesn't fall far from the tree.

Nov 14 '05 #4
"^_^" <cl********@hot mail.com> wrote in message
news:bt******** **@news1.kornet .net...
conversion from:

a="a";

to

a=0x????;

If there are many unicode strings to convert, how can I do batch-conversion?


You can try the NCBI C++ Toolkit. It is portable and free.
http://www.ncbi.nlm.nih.gov/IEB/Tool...DOC/index.html

It contains, among other things, some utility functions for converting
characters and strings from ascii to unicode.
http://www.ncbi.nih.gov/IEB/ToolBox/.../util/utf8.hpp

HTH
Tom
Nov 14 '05 #5
^_^
I'm sorry that I was rude to speak unpolite broken English.

It's my fault. I am not an English speaker

Though, I can speak more correct expression, I was neglect.

Sorry.
What I want is to convert Unicode characters in source code to 0x??? format.

Then it is going to be saved as ASCII format a documents.

Written in not-Latin format Unicode characters in source code cause that
English OS users can not read it without fonts.

If source code's format were saved as UTF8, compiler reads it automatically.

But I don't want this method.

I want to know, either, that convert decimal format numbers to hexademical
format.

For example, I'll show an source.

example.cpp:

#define MAX 16777215
void main(){
if (MAX==a) printf("wrong\n ";);
}

example_I_wante d.cpp
#define MAX 0xFFFFFF <------*this part*
void main(){
if (MAX==a) printf("wrong\n ";);
}

To do so, C or C++ source parsing->converting DEC to HEX->saving CPP file
with converted characters are needed.

I don't know detailed metheds.

If gurus like you give me some good ways, I will follow your wisdom.

Thank you and I'm sorry again.

"Morris Dovey" <mr*****@iedu.c om> wrote in message
news:ah******** ********@news.u swest.net...
Stephen Howe wrote:
I don't think this guy speaks English that well, it is a
foreign language to him, hence the cryptic messages. Probably
Chinese.


[Reading in news:comp.lang. c]

No need to guess. From cleansugar's header:

Organization: Korea Telecom
Message-ID: <bt**********@n ews1.kornet.net >

I think the OP wants a tool that can be used to convert string
literals to unicode equivalents in C and/or C++ source files.

Can someone who knows more about this than I either redirect or
provide help?
--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c
Read my lips: The apple doesn't fall far from the tree.

Nov 14 '05 #6
^_^ <cl********@hot mail.com> scribbled the following
on comp.lang.c:
What I want is to convert Unicode characters in source code to 0x??? format. Then it is going to be saved as ASCII format a documents. Written in not-Latin format Unicode characters in source code cause that
English OS users can not read it without fonts. If source code's format were saved as UTF8, compiler reads it automatically. But I don't want this method. I want to know, either, that convert decimal format numbers to hexademical
format. For example, I'll show an source. example.cpp: #define MAX 16777215
void main(){
if (MAX==a) printf("wrong\n ";);
} example_I_wante d.cpp
#define MAX 0xFFFFFF <------*this part*
void main(){
if (MAX==a) printf("wrong\n ";);
}


You don't *HAVE* to do this. As numbers, 16777215 and 0xFFFFFF are
completely interchangable within a C or C++ program. The runtime
program will only see them as a pattern of bits anyway.

And void main() is an illegal form of main(). Use int main().

So, the answer to your question is: your programs should work fine as
they are.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Life without ostriches is like coffee with milk."
- Mika P. Nieminen
Nov 14 '05 #7
^_^ wrote:
I'm sorry that I was rude to speak unpolite broken English.
It's my fault. I am not an English speaker
That's OK, it wasn't rude, nor was your English unpolite in any way. (By
the way, the normal English word is "impolite." "Unpolite" is perfectly
logical and understandable, but it disappeared from normal English use in
the early 18th century.) The problem is that you didn't give us a question
that we could understand. Many people who *are* native English speakers
fail to do this.

Posting to both C and C++ newsgroups is likely an error. C and C++ are
different languages, and, even when the languages admit the same forms of
code, the normal idioms in the two languages are different. It makes sense
to post to both _only_ when the question has the same answers in both
languages. Since you can't know this, since you would then already know
the answer, it is best to post to a newsgroup for the language you are using.
Though, I can speak more correct expression, I was neglect.
As a side note, you might consider comp.usage.engl ish as another newsgroup
you might post in, if improving your English is important to you. The
above line, for example, might more idiomatically be written, "However, I
can express myself better. I was negligent [or neglectful]."

What I want is to convert Unicode characters in source code to 0x??? format.
If you can read the Unicode characters into a buffer, you can convert those
chars into an integer, as long as the total number of bytes in a character
is less than the sizeof the integer (best unsigned) type that you use.

I want to know, either, that convert decimal format numbers to hexademical
format.
Numbers as stored are simply binary, interpreted for humans as in some base.
Suppse you have an unsigned int
unsigned int a = 263;
We can display this as octal
printf("%#o\n", a); /* displays 0407 */
or hex
printf("%#x\n", a); /* displays 0x107 */
or decimal
printf("%u\n",a ); /* displays 263 */

For example, I'll show an source.

example.cpp:

#define MAX 16777215
void main(){
main always returns an int. "void" is wrong. Don't do this.
if (MAX==a) printf("wrong\n ";);
Even though this is an example of an input file, it is best not to post
hopeless code.
The variable 'a' is undeclared.
The C++ people may object that "printf" is too un-C++-like and complain
that <cstdio> is not #included.
The C people might complain that <stdio.h> is not #included. People
using compilers without C99 conformance (almost all), may complain
that main should actually return a value; 0 is common for successful
completion and EXIT_SUCCESS and EXIT_FAILURE are available if
<stdlib.h> is #included.
}

example_I_wante d.cpp
#define MAX 0xFFFFFF <------*this part*
void main(){
main always returns an int. "void" is wrong. Don't do this.
if (MAX==a) printf("wrong\n ";);
}

To do so, C or C++ source parsing->converting DEC to HEX->saving CPP file
with converted characters are needed.


To parse an input file containing a C program is probably beyond you at the
moment. You will need to detect sequence of characters that might be an
integer, determine that it is one (this requires examining its context),
and probably checking the use for signedness.

It is probably better for you to edit these files by hand. It is largely
because of the occurances "void main()" that I presume that your computing
skills are not up to writing such a program. If I am in error, I apologize.

--
Martin Ambuhl
Nov 14 '05 #8
^_^ <cl********@hot mail.com> scribbled the following
on comp.lang.c:
Why I want 0x???? is easy reading.


Oh, now I see. Well, I don't have any ready-made solution for changing
the decimal values to hexadecimal ones. Sorry for wasting your time
answering the wrong question.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The question of copying music from the Internet is like a two-barreled sword."
- Finnish rap artist Ezkimo
Nov 14 '05 #9
^_^
Why I want 0x???? is easy reading.
"Joona I Palaste" <pa*****@cc.hel sinki.fi> wrote in message
news:bt******** **@oravannahka. helsinki.fi...
^_^ <cl********@hot mail.com> scribbled the following
on comp.lang.c:
What I want is to convert Unicode characters in source code to 0x??? format.
Then it is going to be saved as ASCII format a documents.
Written in not-Latin format Unicode characters in source code cause that
English OS users can not read it without fonts.

If source code's format were saved as UTF8, compiler reads it

automatically.
But I don't want this method.

I want to know, either, that convert decimal format numbers to

hexademical format.

For example, I'll show an source.

example.cpp:

#define MAX 16777215
void main(){
if (MAX==a) printf("wrong\n ";);
}

example_I_wante d.cpp
#define MAX 0xFFFFFF <------*this part*
void main(){
if (MAX==a) printf("wrong\n ";);
}


You don't *HAVE* to do this. As numbers, 16777215 and 0xFFFFFF are
completely interchangable within a C or C++ program. The runtime
program will only see them as a pattern of bits anyway.

And void main() is an illegal form of main(). Use int main().

So, the answer to your question is: your programs should work fine as
they are.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Life without ostriches is like coffee with milk."
- Mika P. Nieminen

Nov 14 '05 #10

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

Similar topics

8
3098
by: Thomas | last post by:
I am currently passing email messages over XML_RPC as the payload for a certain function call. On some of these messages, XML_RPC blows up on the server side and says something to the effect of: exceptions.UnicodeDecodeError: 'utf8' codec can't decode byte 0xa0 in position 1599: unexpected code byte Using the native Python codec for doing conversions gives me a similar error ('utf8' codec can't decode byte 0x93 in position 1328:...
3
1780
by: Roger Thornhill | last post by:
Hi - I have a question that I am sure is a basic UNICODE question for anyone out there with UNICODE experience. I simply would like to see a non-Latin unicode character printed to my console. To do that, I have been attempting to:
2
10978
by: Irfan Bondre | last post by:
When I try to create a table with a vargraphic column I get the following error. CREATE TABLE EIITEST.IRFAN ("VARC" VARCHAR (48) , "VARGRA" VARGRAPHIC (96) ) DATA CAPTURE NONE IN USERSPACE1; ---------------------------------------------------------------------------- - DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL1216N Graphic...
4
5253
by: LinasB | last post by:
Hi, How to read system setting value of "Language for non-Unicode programs" ? Or how to set it programmatically? LinasB
3
3457
by: Richard Connamacher | last post by:
I'm new to PostgreSQL, and from the looks of it, it's a great database, and I'll be using more of it in the future. I had a quick question if anyone could clear this up. The documentation for PostgreSQL (version 7.1, the version this server is using) says that it supports multibyte character encodings like Unicode (which implies UTF-16 encoding). Later on, the same page says that Unicode is represented using UTF-8 encoding. UTF-8 is the...
1
1446
by: Steve Marshall | last post by:
Hi all, This is probably a real dumb question, but I just haven't come across the answer... Is there a simple way to treat a byte array as a string, or to convert it to a string? And the converse would sometimes be useful too, i.e. convert/treat string as byte array. Thanks
4
1268
by: ProvoWallis | last post by:
I'm totally stumped by this problem so I'm hoping someone can give me a little advice or point me in the right direction. I have a file that looks like this: <SC>APPEAL<XC>40-24; 40-46; 42-46; 42-48; 42-62; 42-63 <SC>PROC GUIDE<XC>92<LT>1(b)(1) (i.e., <<SC><XC><SC><XC><LT>
2
1235
by: Rob | last post by:
Hello, We are in the process of writing an application that is unicode compliant. The question that I have is what unicode font should be used for all of our forms? Currently we are using Arial Unicode but we have come across instances where users don't have this font. Is there a unicode font gauranteed to be included with Windows XP or can this font be distributed with our application? Thanks,
6
1892
by: Rob | last post by:
Is there a handy .NET call to convert a Unicode string to valid HTML so sticking in an <pinner HTML? Kind of thing converts "<" to &lt and multiple spaces to &nbsp etc. I need to display unicode text from a database on the web page. Cheers, Rob.
13
3942
by: Liang Chen | last post by:
Hope you all had a nice weekend. I have a question that I hope someone can help me out. I want to run a Python program that uses Tkinter for the user interface (GUI). The program allows me to type Chinese characters, but neverthelss is unable to show them up on screen. The follow is some of the error message I received after I logged off the program: "Could not write output: <type "exceptions: UnicodeEncodeError'>, 'ascii' codec can't...
0
9886
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10706
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10338
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9482
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7056
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5719
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4528
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
3
3164
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.