formatting binary numbers in c#
int value = 31;
string binary = Convert.ToString(value, 2);
Console.WriteLine(binary.PadLeft(8, '0')); // Outputs "00011111"
formatting binary numbers in c#
int value = 31;
string binary = Convert.ToString(value, 2);
Console.WriteLine(binary.PadLeft(8, '0')); // Outputs "00011111"
c# string to binary
public static byte[] ConvertToByteArray(string str, Encoding encoding)
{
return encoding.GetBytes(str);
}
public static String ToBinary(Byte[] data)
{
return string.Join(" ", data.Select(byt => Convert.ToString(byt, 2).PadLeft(8, '0')));
}
// Use any sort of encoding you like.
var binaryString = ToBinary(ConvertToByteArray("Welcome, World!", Encoding.ASCII));
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us