Menu Close

Go – How to get IEEE 754 binary representation of number with Float32bits in go

Here, We will learn how to get IEEE 754 binary representation of number with Float32bits in go. We can get it by using Float32bits() function in math package in go golang.

Function prototype:

func Float32bits(no float32) uint32

Return value:

Float32bits() function in math package returns the
IEEE 754 binary representation of number with the
sign bit of number.
It gives result in the same bit position

Float32bits(Float32frombits(no)) == no

Example with code:

package main

import (
  "fmt"
  "math"
)

func main() {

  no := math.Float32bits(2)
  fmt.Println(no)

  no = math.Float32bits(1)
  fmt.Println(no)

  no = math.Float32bits(2.12)
  fmt.Println(no)

  no = math.Float32bits(3.4)
  fmt.Println(no)
  
}

Output:

1073741824
1065353216
1074245140
1079613850

To learn more about golang, Please refer given below link:

https://techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang, math

Leave a Reply

Your email address will not be published. Required fields are marked *