tags:

views:

178

answers:

4

hi all can anyone help me in converting the data from unicode(16bit) to 7bit ascii in c++ language thanx

+4  A: 

You can map unicode chars 0..127 to the ASCII set. For the other chars there is no 7 bit ASCII equivalent. What do you want to do with those?

Gamecat
+2  A: 

There is nothing in the C++ language itself for handling such conversions. You have to use RTL/API functions instead. For instance, if your app is running on the Windows platform, it can use the Win32 API WideCharToMultiByte() function. If you want something more portable, look at GNU's iconv library.

Or, you can simply perform the conversion manually. Unicode UTF-16 is very easy to decode by hand, and from there values 0-127 are the ASCII values.

Remy Lebeau - TeamB
Thanx alot 4 answring
dweep
+1  A: 

You want to convert double-byte unicode characters into utf7 which will give you characters that can be represented in the ascii character set (and avoid being garbled by antique systems that cant handle characters with the highest bit set). Note that this will split up a multibyte character into several characters (if read as ascii).

Example code can be found at ibiblio.org (from a quick google search). Unknown license.

Simon Svensson
Use UTF-8 instead of UTF-7. All ASCII characters are represented as-is in UTF-8, and do not use multiple bytes per character. The same cannot be said for UTF-7, as some ASCII characters are reserved and need encoding. Plus, UTF-7 is more complex than UTF-8, as it incorporates both UTF-16 and a modified version of Base64 for any characters it needs to encode. UTF-8 does not do any of that.
Remy Lebeau - TeamB
Yes, utf-8 is prefered, but the original question implied that he wanted characters that could be represented in 7 bit.
Simon Svensson
A: 

To pack 16-bit data to 7-bit you could use Boost.Serialization Library

Kirill V. Lyadvinsky