BitConverter.GetBytes Method (Boolean)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Returns the specified Boolean value as a byte array.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

Public Shared Function GetBytes (
	value As Boolean
) As Byte()

Parameters

value
Type: System.Boolean

A Boolean value.

Return Value

Type: System.Byte()

A byte array with length 1.

You can convert a byte array back to a Boolean value by calling the ToBoolean method.

The following example converts the bit patterns of Boolean values to Byte arrays with the GetBytes method.

Module Example
   Public Sub Main()
      ' Define Boolean true and false values.
      Dim values() As Boolean = { true, false }

      ' Display the value and its corresponding byte array.
      Console.WriteLine("{0,10}{1,16}", "Boolean", "Bytes")
      Console.WriteLine()

      For Each value In values
         Dim bytes() As Byte = BitConverter.GetBytes(value) 
         Console.WriteLine("{0,10}{1,16}", value, 
                           BitConverter.ToString(bytes))
      Next
    End Sub 
End Module
' The example displays the following output:
'        Boolean           Bytes
'     
'           True              01
'          False              00

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: