.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 11th, 2007, 11:57 AM
adriyel adriyel is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 2 adriyel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 16 m 13 sec
Reputation Power: 0
C# Hexadecimal/ASCII and String Termination Problems [PLEASE HELP]

EDIT: Sorry for the inconsistency but I re-edited my whole post, lol.
I still have a problem, just a different one, so no need to delete the thread.

New problem: I have successfully read the bytes of a file into a byte array. The hex of the file is successfully being placed into a textbox. The ascii is properly placed into the adjunct textbox if it is a text file. Binary files don't play nice, are the nulls in a binary file terminating it or something? (I'm really a C language fogey).

Why does the ASCII textbox terminate with binary files?
Furthermore, how can I segment the output of the hex into batches of 2 and lines of 16?

EDIT: Could anyone also help me with figuring out how
to link my Hexadecimal and ASCII textboxes together
so that highlighting in one highlights the same byte in the other and also links together the scrolling thereof and so on and so forth?

Sample Code:
Code:
                long filesize;
             
                //declared some utility variables

                txtHex.Text = "";
                txtASCII.Text = "";
                //blanked the textbox
                
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = "All Files|*.*";
                ofd.ShowDialog();
                
                //opened file from openfiledialog for reading
                try
                {
                    FileStream fs = new FileStream(ofd.FileName, FileMode.Open,
                       FileAccess.Read, FileShare.Read);
                    filesize = fs.Length;
                

                byte[] bytes = new byte[filesize];
                BinaryReader br = new BinaryReader(fs);
                bytes = br.ReadBytes((int)filesize);

                label2.Text = Convert.ToString(bytes.Length) + " bytes";

                StringBuilder stringb = new StringBuilder();
                for (int i = 0; i < bytes.Length; i++)
                {
                    stringb.Append(bytes[i].ToString("X2"));
                }

                txtHex.Text = stringb.ToString();
                txtASCII.Text = System.Text.ASCIIEncoding.ASCII.GetString(bytes);
                }

                catch (Exception)
                {
                    return; 
                    // this is to solve an error where it would crash if you hit cancel
                }

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > C# Problem


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap