How to get bits of a float value in VB.NET

1 Answer

0 votes
Imports System
Imports System.Linq

Public Class Program
    Public Shared Sub Main(ByVal args As String())
        Dim value As Single = 3.14F
		
        Dim bytes = BitConverter.GetBytes(value).Reverse() _
					.Select(Function(x) Convert.ToString(x, 2)) _
					.Select(Function(x) x.PadLeft(8, "0"c)) _
					.Aggregate("0b", Function(a, b) a & "_" & b)
					
        Console.WriteLine(bytes)
    End Sub
End Class


' https://www.h-schmidt.net/FloatConverter/IEEE754.html
		
		
' run:
'
' 0b_01000000_01001000_11110101_11000011
'

 



answered Sep 3, 2023 by avibootz

Related questions

...