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

Need explaination for Unicode funda

153 100+
Expand|Select|Wrap|Line Numbers
  1. namespace consolepractice
  2. {
  3.     class Program
  4.     {
  5.         static byte[] asyncreadbytes;
  6.         static byte[] asyncwritebytes;
  7.         static FileStream fileS;
  8.         static FileInfo file;
  9.  
  10.         static void Main(string[] args)
  11.         {
  12.  
  13.             file = new FileInfo(@"c:\akshay.pallu");
  14.             fileS = file.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite);
  15.  
  16.             AsyncCallback readcallback = new AsyncCallback(readfunc);
  17.             AsyncCallback writecallback = new AsyncCallback(writefunc);
  18.  
  19.             asyncwritebytes = System.Text.Encoding.Unicode.GetBytes("luck");
  20.             foreach (byte b in asyncwritebytes)
  21.                 Console.Write((char)b);
  22.  
  23.  
  24.             Console.WriteLine("\nBegin writing....");
  25.             Console.WriteLine("No of bytes=" + asyncwritebytes.Length);
  26.             fileS.Position = 0;
  27.             fileS.BeginWrite(asyncwritebytes, 0, 8, writecallback, asyncwritebytes);
  28.  
  29.             asyncreadbytes = new byte[8];
  30.             Console.WriteLine("Begin reading....");
  31.             fileS.Position = 0;
  32.             fileS.BeginRead(asyncreadbytes, 0, 8, readcallback, asyncreadbytes);
  33.  
  34.  
  35.             Console.ReadKey();
  36.         }
  37.         static void writefunc(IAsyncResult result)
  38.         {
  39.             Console.WriteLine("written.");
  40.             fileS.EndWrite(result);
  41.         }
  42.  
  43.         static void readfunc(IAsyncResult result)
  44.         {
  45.             Console.Write("Read this--->");
  46.             foreach (byte b in (byte[])result.AsyncState)
  47.                 Console.Write((char)b);
  48.             fileS.EndRead(result);
  49.         }
  50.  
  51.     }
  52. }

I need to know why the output is l u c k and not luck.

What i can figure out is this:
the character 'l' gets stored as unicode (16 bits).
The low order byte store the char l (binary calue 108) as [01101100] and the high order byte stores all zeroes[00000000] so the char is stored as

[00000000] [01101100].

All the other characters are stored in the same way (the most siignificant byte being made up of all zeroes).

All the tiem of reading we read byte wise.
so the[00000000] byte is read first which when casted to unicode char(char) tp produce the equivalent character.But sadly this does not happen as it is printed as l<space>u<space>
not as <space>l<space>u

WHY IS IT SO
Oct 3 '08 #1
0 814

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Bernd Preusing | last post by:
Hi, today I (Python beginner) ran into a problem:^ I have a JPG file which contains some comment as unicode. After reading in the string with s=file.read(70) from file offest 4 I get a...
4
by: Chris | last post by:
Hi, I found this code that can solve a problem I have. It sends print direct to printer. Imports System Imports System.Text Imports System.Runtime.InteropServices ...
3
by: Buddy Robbins | last post by:
Hey folks, I'm trying to use the PathCleanupSpec function from the shell library. The function prototype is: int PathCleanupSpec( LPCWSTR pszDir, LPWSTR pszSpec) In the old days of VB6, I...
4
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
40
by: apprentice | last post by:
Hello, I'm writing an class library that I imagine people from different countries might be interested in using, so I'm considering what needs to be provided to support foreign languages,...
2
by: Frantic | last post by:
I'm working on a list of japaneese entities that contain the entity, the unicode hexadecimal code and the xml/sgml entity used for that entity. A unicode document is read into the program, then the...
5
by: Jon Bowlas | last post by:
Hi listers, I wrote this script in Zope some time ago and it worked for a while, but now I'm getting the following error: TypeError: coercing to Unicode: need string or buffer, NoneType found ...
0
by: Joe | last post by:
Hi Could someone give me a simple explaination of this XSD which is a DataSet with relations The tables are fgFAT,e0,e1,e2,e3 which I have deleted I am trying to make sense of the part below...
29
by: Ioannis Vranos | last post by:
Hi, I am currently learning QT, a portable C++ framework which comes with both a commercial and GPL license, and which provides conversion operations to its various types to/from standard C++...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...

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.