TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
jack jack
NA
2
4.1k
Binary File Read and Split and Convert
Feb 11 2014 12:21 PM
Hi im trying to read a binary file and convert it to ascii....
there are two steps im trying to accomplish:-
1. Read the binary file and split first 4 bytes and then consecutive 32 bytes continuously for 10 times.
2. The individual bits then needs to be converted to ascii.
The image attached will give more information on the above.
(http://postimg.org/image/at015uhn1/)
http://postimg.org/image/at015uhn1/
Issue what im facing is im able to read the binary file but im not able to split and convert.
Snippet what im using :-
var fs = new FileStream(@"C:\csharpcorner.bin", FileMode.Open);
var len = (int)fs.Length;
var bits = new byte[len];
fs.Read(bits, 0, len);
// Dump 16 bytes per line
for (int ix = 0; ix < len; ix += 16)
{
var cnt = Math.Min(16, len - ix);
var line = new byte[cnt];
Array.Copy(bits, ix, line, 0, cnt);
// Write address + hex + ascii
Console.Write("{0:X6} ", ix);
Console.Write(BitConverter.ToString(line));
Console.Write(" ");
// Convert non-ascii characters to .
for (int jx = 0; jx < cnt; ++jx)
if (line[jx] < 0x20 || line[jx] > 0x7f) line[jx] = (byte)'.';
console.writeline(Encoding.ASCII.GetString(line));
}
Console.Readline();
Reply
Answers (
1
)
Converting Byte Array to Integer Array
How to update a MasterClass wch inherts detail class