Click here to Skip to main content
13,049,684 members (64,173 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I've created a text file Encoded in ASCII. It Contains the Following Text;


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 21:40pm
DaveAuld 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
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:
Pravinda Amarathunge 4-Dec-11 4:24am
Rate this: bad
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)))

For more reference :-
How do you convert a string to ascii to binary in C#[^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 4 Mar 2013
Copyright © CodeProject, 1999-2017
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