Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# binary
I've created a text file Encoded in ASCII. It Contains the Following Text;
 
abcd123
 
Binary value of the above text ;
 
01100001 01100010 01100011 01100100 0110001 0110010 0110011 
 
How Can I do this (getting binary value of a file to a text box) in C# ?
Posted 3-Dec-11 22:40pm
Comments
DaveAuld at 4-Dec-11 3:43am
   
Sounds like a homework question to me. There are various ways to achieve this, but i'm sure this must have been covered in you course notes?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Reading text is easy: MSDN[^]
byte[] data = File.ReadAllBytes(path);
Converting to binary is easy: MSDN[^]
string s = Convert.ToString(myByte, 2);
Put them together with a foreach loop and a StringBuilder and you have a program...
 
But, since this is your homework, I'm leaving the actual code to you! Laugh | :laugh:
  Permalink  
Comments
Pravinda Amarathunge at 4-Dec-11 4:24am
   
thanks
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can also to it by using LINQ
var str = "abcd123";
           foreach (string letter in str.Select(c => Convert.ToString(c, 2)))
           {
               Console.WriteLine(letter);
           }
           Console.ReadLine();
For more reference :-
How do you convert a string to ascii to binary in C#[^]
  Permalink  
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 BillWoodruff 173
3 Sergey Alexandrovich Kryukov 170
4 PIEBALDconsult 160
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 4 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100