Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I need to convert text to binary in c #, appreciate the help or some example thanks in advance.
Posted
Updated 14-Mar-22 7:41am
Comments
Fredrik Bornander 11-Nov-13 9:40am    
Elaborate please, what do you mean by "binary" in this context?
public X ConvertToBinary(string source);

What type would X be?
Richard MacCutchan 11-Nov-13 12:57pm    
You have already asked this question once today and I told you to ask your teacher what he or she means by "convert text to binary".

This question makes no sense at all. All files are binary, including "text" files.

Very often, the object or executable files are called "binary". And the code is written in the form of text files, these files are called "source code". In that sense, compilation (compilation and linking) really produced "binary" files from "text" files. But it has nothing to do with "conversion" or something like that.

—SA
 
Share this answer
 
Comments
CPallini 11-Nov-13 13:16pm    
5.Tell them, tell them. :-)
Sergey Alexandrovich Kryukov 11-Nov-13 13:53pm    
... :-)
Thank you, Carlo.
—SA

I guess you could mean something like
C#
byte[] binary = System.Text.Encoding.Unicode.GetBytes(yourString);

Depending on your exact requirements, you may need a different encoding than Unicode.
To reverse the process (i.e. get your string back from the bytes), use
C#
string yourString = System.Text.Encoding.Unicode.GetString(binary);
 
Share this answer
 
Hi
You can view few of the samples in below post

convert string to binary and overhand[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900