Convert a Boolean to a Byte in C#

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);

Up Next
    Ebook Download
    View all
    Learn
    View all