Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

save binary data to file c#

// The string we are working with.
string str = @"1010101010010100010101101";
// The number of bits in a 64 bit integer!
int size = 64;
// Pad the end of the string with zeros so the length of the string is divisible by 64.
str += new string('0', str.Length % size);
// Convert each 64 character segment into a 64 bit integer.
long[] binary = new long[str.Length / size]
    .Select((x, idx) => Convert.ToInt64(str.Substring(idx * size, size), 2)).ToArray();
// Copy the result to a byte array.
byte[] bytes = new byte[binary.Length * sizeof(long)];
Buffer.BlockCopy(binary, 0, bytes, 0, bytes.Length);
// Write the result to file.
File.WriteAllBytes("MyFile.bin", bytes);
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to set the server url in dotnet core 
Csharp :: dbset properties 
Csharp :: inheritance in c# 
Csharp :: list view in unity 
Csharp :: ssml 
Csharp :: c# object add property 
Csharp :: linq syntax 
Csharp :: loop in c# 
Csharp :: how to remove from list from index c# 
Csharp :: linq where condition c# 
Csharp :: FiveM pc key code 
Csharp :: EF .NET4 INSERT IMPROVE PERFORMACE 
Csharp :: logical operators in c# 
Csharp :: access server name or ip c# get 
Csharp :: unity fast sin 
Csharp :: asp.net store list in web.config 
Csharp :: ef save changes 
Csharp :: c# nunit assert.contains 
Csharp :: blazor editform empty 
Csharp :: unity set dictionary value 
Csharp :: c# multipthreading 
Csharp :: // Force WPF to render UI changes immediately with this magic line of code... 
Csharp :: how to navigate between page in wpf 
Csharp :: mono cast 
Csharp :: c# set two dimensional array 
Csharp :: epplus how to align text to right 
Csharp :: take the last 50 from array c# 
Csharp :: how to call void unity 
Csharp :: Custom Circular Picture Box C# win Form app 
Csharp :: WPF combobox filter as you type 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =