Re: I cannot reliably write the Hex number "83" to a stream



ajmastrean wrote:
I cannot get any (hex) number in the "0x80"-"0x89" range (inclusive)
to write properly to a file. Any number in this range magically
transforms itself into "0x3F". For instance, debugging shows that
"0x83" = UInt16 "131" and that converts to Char (curly) "f". Any
information would be helpful.

String[] hexNum = { "79", "80", "89", "90" };
System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(@"C:
\test.dbf", true, System.Text.Encoding.Default);

foreach (String hex in hexNum)
{
Char hexChar = (Char)UInt16.Parse(hex,
System.Globalization.NumberStyles.HexNumber);
streamWriter.Write(hexChar);
}

streamWriter.Flush();
streamWriter.Close();

Have you looked at the default encoding and what it does to your data?
Since you're writing text characters through an encoding object, it will in some cases encode the characters different than if you just output pure bytes to begin with.

--
Lasse Vågsæther Karlsen
mailto:lasse@xxxxxxxxxxx
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
.



Relevant Pages

  • Re: Text Box or String > 32K -- Problem?
    ... >lengths on various fields and objects while debugging the code. ... 120K characters will never fit into a text box. ... bridges an old A2 back end data mdb to an A97 front end. ...
    (microsoft.public.access.formscoding)
  • Re: datainput stream
    ... DataInputStream has a constructor that takes InputStream ... there is a difference between bytes and characters. ... This _STREAM_ reads the bytes, ... Your program transforms the bytes into characters by way of the ...
    (comp.lang.java)
  • TADOQuery.SQL.Text - unwanted trailing characters
    ... I have a TADOQuery object and am trying to set the SQL.Text property. ... When debugging the ADOQueryUpdate.SQL.Text has some unwanted trailing ... characters: 'update TABLE set COLUMN = VALUE where COLUMN = ...
    (borland.public.delphi.database.ado)
  • Re: Why does my program change the characters in my shell
    ... > I'd like to know what the typical reason for this is. ... However, when it gets done puting the data on stdout, the program is ... > characters, just right angled shapes and stuff. ...
    (comp.unix.programmer)
  • RE: Weird TraceListener NewLine problem
    ... debugging, I think the mail message should also contain the characters. ... Steven Cheng ...
    (microsoft.public.dotnet.general)