Click here to Skip to main content
15,905,875 members
Home / Discussions / C#
   

C#

 
AnswerRe: Variable Declared Pin
Christian Graus22-Jul-07 18:57
protectorChristian Graus22-Jul-07 18:57 
AnswerRe: Variable Declared Pin
Sathesh Sakthivel22-Jul-07 19:23
Sathesh Sakthivel22-Jul-07 19:23 
QuestionData Transfer Pin
Le Hoang Viet22-Jul-07 18:34
Le Hoang Viet22-Jul-07 18:34 
AnswerRe: Data Transfer Pin
Christian Graus22-Jul-07 18:48
protectorChristian Graus22-Jul-07 18:48 
QuestionWebcam Server Pin
Le Hoang Viet22-Jul-07 15:51
Le Hoang Viet22-Jul-07 15:51 
AnswerRe: Webcam Server Pin
Christian Graus22-Jul-07 17:04
protectorChristian Graus22-Jul-07 17:04 
QuestionBinary into ASCII Pin
ScIeNcE_ErRoR22-Jul-07 15:01
ScIeNcE_ErRoR22-Jul-07 15:01 
AnswerRe: Binary into ASCII Pin
Luc Pattyn22-Jul-07 15:24
sitebuilderLuc Pattyn22-Jul-07 15:24 
Hi,

for the matter at hand, all characters are stored in either 1 or 2 bytes, and use
either 8 or 16 bits (i.e. there may be leading zero bits).

ASCII characters use 1 byte with 7 significant bits; there are extensions (such as ANSI) that
use all 8 bits in the byte.
Unicode characters use 2 bytes with 16 significant bits.

Some Windows functions may pack an ASCII character together with some flags (e.g. regarding
the state of the control, alt, and windows key), resulting in a 2-byte short or a 4-byte int.
That is useful for a keyboard state or so, but does not apply to text, or parts thereof.

A piece of text consists of a sequence of characters, and since these could be either 1 byte
or 2 byte, we need some encoding scheme. There are many.

The simplest one is all ASCII (hence 1 B/char), but this one has a lot of limitations.
Another one would be all Unicode (hence 2 B/char), that is expensive (especially in
storage or data communication).
Some mixed forms exist such as UTF8, they try to use 1B for popular characters, and more
when necessary.

If you are holding an array of bytes, and know what encoding scheme was used,
go have a look at the Encoding class: instantiate an Encoding object corresponding
to the way the text got encoded, then call its GetChars() method to decode the byte array,
the result is a string (now in Unicode, whatever it originally was).
That's what you asked for, isnt it.

There is more though. When encoding (i.e. from text to bytes) into Unicode, UTF8 and
then some, the convention is to prefix a 2-byte code indicating which encoding is used;
when using the correct way to decode such a byte stream, these optional markers get
consumed and cause the selection of the right decoder automatically.
This happens for instance in File.ReadAllText

Hope this clarifies a lot.




GeneralRe: Binary into ASCII Pin
ScIeNcE_ErRoR22-Jul-07 16:05
ScIeNcE_ErRoR22-Jul-07 16:05 
GeneralRe: Binary into ASCII Pin
Luc Pattyn22-Jul-07 17:23
sitebuilderLuc Pattyn22-Jul-07 17:23 
GeneralRe: Binary into ASCII Pin
ScIeNcE_ErRoR23-Jul-07 13:51
ScIeNcE_ErRoR23-Jul-07 13:51 
GeneralRe: Binary into ASCII Pin
Luc Pattyn23-Jul-07 14:17
sitebuilderLuc Pattyn23-Jul-07 14:17 
QuestionPowerPoint Pin
half-life22-Jul-07 13:25
half-life22-Jul-07 13:25 
AnswerRe: PowerPoint Pin
Paul Conrad22-Jul-07 15:53
professionalPaul Conrad22-Jul-07 15:53 
AnswerRe: PowerPoint Pin
Luc Pattyn22-Jul-07 17:33
sitebuilderLuc Pattyn22-Jul-07 17:33 
GeneralRe: PowerPoint Pin
Paul Conrad22-Jul-07 18:26
professionalPaul Conrad22-Jul-07 18:26 
GeneralRe: PowerPoint Pin
Luc Pattyn23-Jul-07 1:18
sitebuilderLuc Pattyn23-Jul-07 1:18 
GeneralRe: PowerPoint Pin
Paul Conrad23-Jul-07 5:59
professionalPaul Conrad23-Jul-07 5:59 
QuestionFind a Button with HitTest Pin
donovan.solms22-Jul-07 12:00
donovan.solms22-Jul-07 12:00 
AnswerRe: Find a Button with HitTest Pin
Luc Pattyn22-Jul-07 12:24
sitebuilderLuc Pattyn22-Jul-07 12:24 
GeneralRe: Find a Button with HitTest Pin
donovan.solms22-Jul-07 13:10
donovan.solms22-Jul-07 13:10 
GeneralRe: Find a Button with HitTest Pin
Luc Pattyn22-Jul-07 13:44
sitebuilderLuc Pattyn22-Jul-07 13:44 
QuestionThe Location of the cursor in a Text Box Pin
max2929722-Jul-07 11:23
max2929722-Jul-07 11:23 
AnswerRe: The Location of the cursor in a Text Box Pin
Christian Graus22-Jul-07 11:27
protectorChristian Graus22-Jul-07 11:27 
AnswerRe: The Location of the cursor in a Text Box Pin
mav.northwind22-Jul-07 19:17
mav.northwind22-Jul-07 19:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.