473,761 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array of Bytes to Unicode chars (ISO-8859-1)

Hi ,
I want to convert an array of bytes like :

{79,104,-37,-66,24,123,30,-26,-99,-8,80,-38,19,14,-127,-3}

into Unicode character with ISO-8859-1 standard.

Can anyone help me .. how should I go about doing it ?

Thanks

Jul 25 '06
14 6415
In article <44************ **@cam.ac.ukIan Malone <ib***@cam.ac.u kwrites:
....
Not quite, ISO-8859-1 includes characters with the most significant
bit set (ie. 128-255). The low range matches (I believe, but could
be wrong...) ASCII, the printable characters of which do map directly
to Unicode. In general you need tables of corresponding characters
to do this, see P J Plauger's post.
Look at the table that P. J. Plaugher posted and see that it starts with:
0x00 0x0000
and goes on to
0xFF 0x00FF
or something like that. The first 256 codes of Unicode are identical to
ISO 8859-1.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Jul 25 '06 #11

Keith Thompson wrote:
"J. J. Farrell" <jj*@bcs.org.uk writes:
ab*****@gmail.c om wrote:
I want to convert an array of bytes like :

{79,104,-37,-66,24,123,30,-26,-99,-8,80,-38,19,14,-127,-3}

into Unicode character with ISO-8859-1 standard.

Can anyone help me .. how should I go about doing it ?
Your question is unclear. Are you saying that the current bit patterns
in the array are ISO 8859-1 encodings, presumably represented as signed
chars? (That is, that if I treat the bit patterns in the array as
unsigned chars, then the low-order 8 bits of each are ISO 8859-1
character values?)

Assuming that, you first need to pick a type with at least 21 value
bits to hold the Unicode characters. Life will usually be less
confusing if you make it an unsigned type. Unsigned long will be big
enough in all versions of Standard C. You then need to put the 8 low
order bits from the each entry in the source array into the 8 low order
bits in the destination entries, with zeroes in the higher bits. Use
pointers to iterate over the arrays doing something like

*targetp = *(unsigned char *)sourcep & 0xff;

The values of ISO 8859-1 characters are the same as the values of the
equivalent Unicode characters.

Assuming sourcep is a char*, I think converting the char value to
unsigned char is clearer than doing a pointer conversion:

*targetp = (unsigned char)*sourcep & 0xff;
Clearer perhaps, but also wrong in some environments given the
assumptions I stated.
The "& 0xff" may be unnecessary of CHAR_BIT==8.
Indeed. But why write it in a way that will be wrong if CHAR_BIT != 8,
when it takes so little extra effort to make it portable?

Jul 26 '06 #12
Simon Biber wrote:
Ian Malone wrote:
>Simon Biber wrote:
>>Simply copy them into the low byte of your Unicode characters!

Not quite, ISO-8859-1 includes characters with the most significant
bit set (ie. 128-255). The low range matches (I believe, but could
be wrong...) ASCII, the printable characters of which do map directly
to Unicode. In general you need tables of corresponding characters
to do this, see P J Plauger's post.

The Unicode character set was designed not only that 0-127 match ASCII,
but also that 128-255 match ISO-8859-1. This works for UTF-16 and UTF-32
but not, of course, UTF-8.
Sorry, my blood caffeine level was obviously dangerously low yesterday.
Hallucinations that occurred involved the fact it won't fit into UTF8
as you mention, and I somehow read low byte as 7 bits...

--
imalone
Jul 26 '06 #13
On Tue, 25 Jul 2006 16:15:10 GMT, Frederick Gotham
<fg*******@SPAM .comwrote:
<snip>
Perhaps something like:

#include <wchar.h>

void ToUnicode(wchar _t *pw, char const *pc)
{
while(*pw++ = *pc++);
}

int main(void)
{
char const str[] = "October is the tenth month of the year.";

wchar_t buf[sizeof str * sizeof(wchar_t)];
The *sizeof(wchar_t ) is unnecessary and wasteful. You need (only) the
same number of wchar_t as there were chars in the source.
ToUnicode(buf,s tr);
}
- David.Thompson1 at worldnet.att.ne t
Aug 7 '06 #14
Dave Thompson posted:
> char const str[] = "October is the tenth month of the year.";

wchar_t buf[sizeof str * sizeof(wchar_t)];
The *sizeof(wchar_t ) is unnecessary and wasteful. You need (only) the
same number of wchar_t as there were chars in the source.

You're correct, I wrote the code quickly and sloppily. I should have written:

char const str[] = "whatever";

wchar_t buf[sizeof str];

--

Frederick Gotham
Aug 7 '06 #15

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

Similar topics

4
1493
by: George VS | last post by:
hi group! is there any table with the unicode standard names in the form: Aacute, U000C1, =capital A, acute accent, .... this was excerpt of W3's "Characters Ordered by Entity Name" table, but it does not contain entites such as &IPAprim; &fixout; &wsmin; ....
2
12979
by: Beat Richli | last post by:
Hello i have following problem with ASP (using Interdev, Win2003 Server): if a special character is entered in a textbox, ASP or the Client Browser (IE 6) seems to convert this character in HTML entities. eg characters on this site: http://unicode.e-workers.de/kyrillisch.php come back as eg Л . i'm not shure, where exactly this happens. it doesn't happen on ASP.NET sites though. the top of those documents looks
6
5623
by: peter pilsl | last post by:
postgres 7.3.2 I store unicode-data in postgresql. The data is retrieved via webinterfaces, processed with perl and then stored in postgresql (and viceversa). All is going nice with one problem. If performing a "select * order by field"-query the result is not what I expected. German umlauts (ie: Ö) are stored as doublechars ("Ö" is "Ö") and only the first char seems to be taken into account when sorting.
1
2181
by: Jorge Cavalheiro | last post by:
Hello I've done research in the SQL Server BOL and i found out how to store greek characters in a field, that's simple use nchar datatype and the unicode('greek chars') to insert/update the field. How do i display then in a datagrid it displays numbers instead of the chars. I didn't find anything useful in the tablestyles.
0
1143
by: simonth | last post by:
hi guys i m writing a VB.NET app using the Oracle Lite database as the data source. Got a problem with inserting unicode chars e.g. chinese into the database when using the dataadapter and dataset insert command. It gave a NullReferenceException. Followings are what i suspect might be causing the problem: 1. olbdbadapter of oracle for .net not able to support unicode 2. oracle lite db not able to support unicode - i have directly...
3
1691
by: gregpinero | last post by:
I want to make a little Python utility where a user can enter the unicode numerical code and get the actual symbol back in utf-8. For example, a user could enter something like u221E And get back $B!g(B Now, this does seem to work: $B!g(B
2
5717
by: Grzegorz Danowski | last post by:
Hello, I have made few reports in rdlc technology. They look and print fine, but if I export any report to pdf file I have some problems with polish specific chars: a. if I open pdf in Acrobat Reader I can't find (ctrl-f) phrases that contains polish letters, b. if I copy a paragraph that contains polish chars and paste to MS Word the text is unreadable: squares instead chars in whole paragraph (not only
2
1821
by: =?Utf-8?B?UmljaA==?= | last post by:
I just got a new workstation - which I had to reload VS2005 (myself). On my old workstation - the VS2005 supported unicode chars in the text of controls. On the new workstation - I just get the little squares when I try to copy a unicode char in the text of a control (like a menu control - specifically a down arrowhead). How can I make this (these) unicode char useable in my apps? While I am at it - when I deploy the app(s) the unicode...
0
9377
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9811
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
8814
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
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
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
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
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.