Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a String to binary sequence in C# [duplicate]

Tags:

string

c#

binary

Possible Duplicate:
How do you convert a string to ascii to binary in C#?

How to convert string such as "Hello" to Binary sequence as 1011010 ?

like image 430
Sudantha Avatar asked May 13 '11 09:05

Sudantha


People also ask

How do you convert a string to binary?

To convert a string to binary, we first append the string's individual ASCII values to a list ( l ) using the ord(_string) function. This function gives the ASCII value of the string (i.e., ord(H) = 72 , ord(e) = 101). Then, from the list of ASCII values we can convert them to binary using bin(_integer) .

Which typecast method is required to store string in a binary file?

WriteFile function (MSDN)


1 Answers

Try this:

string str = "Hello"; 
byte []arr = System.Text.Encoding.ASCII.GetBytes(str);
like image 142
A B Avatar answered Oct 04 '22 03:10

A B