Convert Boolean to Byte in C#

The Convert class in .NET provides conversion functionality from one data type to another data type. These data types include Boolean, Byte, Char, DateTime, Decimal, Double, Int16, Int32, Int64, SByte, Single, String, UInt16, UInt32, and UInt64.

Byte Conversions

A byte is an 8-bit unsigned integer.  The ToByte method of the Convert class converts other base data types to a byte data type.

Convert a Boolean to a Byte

The following code converts a Boolean data type to a byte. 

// Convert a boolean type to a Byte
Console.WriteLine("Convert boolean type to Byte");
bool f = false;
bool t = true;
byte bf = Convert.ToByte(f);
byte bt = Convert.ToByte(t);
Console.WriteLine("{0} converted to {1}.", f, bf);
Console.WriteLine("{0} converted to {1}.", t, bt);



Similar Articles
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.