this is my code and it writes only this symbols in fileout.txt. whats wrong and how to fix it?
byte[] bArray = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
FileStream file_out = new FileStream(@"C:\fileout.txt",
FileMode.Create);
file_out.Write(bArray, 2, 4);
file_out.Close();
sorry, symbols not shown here but why i dont know. this simbols ar something like upside and small r an some other symbols.
Your output is the actual bytes, rather than the characters that represent them to English-speaking humans (and many other languages, but not all).
The characters you would have written are some controls of mostly historical interest, though ANPA-1312 is still used by Associated Press and it uses them:
START OF TEXT Precedes the actual text of the message. (0x01, that you skipped is the start of a heading.
END OF TEXT End of the text. Also, Ctrl+C to end a running DOS program is this control.
END OF TRANSMISSION Goodbye. Used as a log-out character.
ENQUIRY You still there?
Those in your array to print also include:
NULL (null char, not what
nullmeans in C#): Used in some formats to represent the end of a string, “end of meaningful text”, etc.START OF HEADER: Mentioned above.
ACKNOWLEDGE Yes, I’m here. Also used in TCP/IP hand-shaking.
BELL There are still printers out there that will go ding if you send them this.
BACKSPACE Printing
u, then backspace then¨was once how you would writeü. Remember that if Unicode seems more complicated than ASCII. Actually it’s simpler to just have aü. Also back and X and back and X and back and X was an old “delete”!CHARACTER TAB the first of these characters that you are ever likely to use in modern code that isn’t very low level. The “tab” character. Of course, it doesn’t look like much on its own.
What you perhaps wanted was to output the characters,
'0','1', and so on.You could:
Manually encode them.
'0'is 0x30,'1'is 0x31. This is one of those things where you should know how to do it, but not actually do it yourself 99% of the time.Use a textwriter. This takes values of different types and (optionally with defined formatting rules) outputs the text that represents them. Hence
This will convert the bytes to their human-readable equivalent as it goes, and pretty efficiently. It’s the same as if you’d output 0x32, 0x33, 0x34, 0x35, which will look like “2345” when opened in notepad.
You will mostly want to write bytes directly if you’re receiving them from somewhere else (such as having created or obtained an image stream from somewhere) or doing something very low-level.