I have a Binary Data file (Packed Decimal and ASCII mixed) and would
like to convert into ASCII (readable) file.
How to do it in C#? Thanks. 6 27873
Read the file (or section of it) to a byte array, then pass it to
System.Text.Encoding.ASCII.GetString() to return a string containing the
text. Then you can write this to a file or display it or whatever.
HTH
Ciaran O'Donnell
"as*******@lycos.com" wrote:
I have a Binary Data file (Packed Decimal and ASCII mixed) and would
like to convert into ASCII (readable) file.
How to do it in C#? Thanks.
<as*******@lycos.comwrote:
I have a Binary Data file (Packed Decimal and ASCII mixed) and would
like to convert into ASCII (readable) file.
How to do it in C#? Thanks.
It's not entirely clear what you mean. If there's some bits which are
genuinely ASCII, those should presumably be decoded as ASCII. If there
are some bits which are genuinely binary data, you need to work out how
you want to display that data.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jon wrote:
It's not entirely clear what you mean. If there's some bits which are
genuinely ASCII, those should presumably be decoded as ASCII. If there
are some bits which are genuinely binary data, you need to work out how
you want to display that data.
Here is the data stored in binary:
" "," ",""X","","","2",""
" "," ",""5","","","2",""
"CC"," ",""6","A","","","","","","",""
" "," )"," ","","","&RA","","0","170","1","1","
170","","","","","","",""
<as*******@lycos.comwrote:
It's not entirely clear what you mean. If there's some bits which are
genuinely ASCII, those should presumably be decoded as ASCII. If there
are some bits which are genuinely binary data, you need to work out how
you want to display that data.
Here is the data stored in binary:
" "," ",""X","","","2",""
" "," ",""5","","","2",""
"CC"," ",""6","A","????","","","","","",""
" "," )"," ","","","&RA","","0","170","1","1","
170","","","","","","",""
Well, that's not terribly helpful for two reasons:
1) The binary data has already been lost in converting your article
into text
2) Seeing the binary data accurately doesn't tell us how you want it to
be displayed
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Here is a code which suppose to convert:
FileStream iFile = new FileStream(@"c:\test\binary.dat",
FileMode.Open);
long lengthInBytes = iFile.Length;
BinaryReader bin = new BinaryReader(aFile);
byte[] byteArray = bin.ReadBytes((int)lengthInBytes);
System.Text.Encoding encEncoder = System.Text.ASCIIEncoding.ASCII;
string str = encEncoder.GetString(byteArray);
str converts first two binary data even though file has over 4000
bytes. What's going on?
<as*******@lycos.comwrote:
Here is a code which suppose to convert:
FileStream iFile = new FileStream(@"c:\test\binary.dat",
FileMode.Open);
long lengthInBytes = iFile.Length;
BinaryReader bin = new BinaryReader(aFile);
byte[] byteArray = bin.ReadBytes((int)lengthInBytes);
System.Text.Encoding encEncoder = System.Text.ASCIIEncoding.ASCII;
string str = encEncoder.GetString(byteArray);
str converts first two binary data even though file has over 4000
bytes. What's going on?
Treating arbitrary binary data as ASCII text is a very bad idea. Binary
data is *not* ASCII text. You need to work out how you want to
represent that binary data as text, and act accordingly.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Prachi |
last post by:
I want to convert the binary data to string.
I tried doing the same using following peace of code
Function SimpleBinaryToString(Binary)
Dim I, S
For I = 1 To LenB(Binary)
S = S &...
|
by: J. Campbell |
last post by:
OK...I'm in the process of learning C++. In my old (non-portable)
programming days, I made use of binary files a lot...not worrying
about endian issues. I'm starting to understand why C++ makes...
|
by: Adam |
last post by:
Hello,
I'm trying to decifer the data in the table that stores the data in the
binary format. All numbers are placed in varbinary fields. All I know is the
MS SQL 2000 database useing collation...
|
by: Hako |
last post by:
I try this command:
>>> import string
>>> string.atoi('78',16)
120
this is 120 not 4E.
Someone can tell me how to convert a decimal number to hex number? Can
print A, B, C,DEF.
Thank you.
|
by: HNT20 |
last post by:
Hello All
i am new to python language. i am working on a gnuradio project where it
uses python as the primary programming language. i am trying to convert
a message, text, or numbers into binary...
|
by: Harlin Seritt |
last post by:
Hi...
I would like to take a string like 'supercalifragilisticexpialidocius'
and write it to a file in binary forms -- this way a user cannot read
the string in case they were try to open in...
|
by: Serman D. |
last post by:
Hi,
I have very limited C knowledge. I want to convert to output from a
MD5 hash algorithm to printable ascii similar to the output of the
md5sum in GNU coreutils. Any help on how to do the...
|
by: =?Utf-8?B?YmJkb2J1ZGR5?= |
last post by:
I am having a problem converting string to binary and I am hoping someone can
help me out
I have a sql query that does an update that updates a binary field calles
password
...
|
by: Mason |
last post by:
I have tried and tried...
I'd like to read in a binary file, convert it's 4 byte values into
floats, and then save as a .txt file.
This works from the command line (import struct);
In : f =...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
|
by: SueHopson |
last post by:
Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
| |