Convert 32 digit value to String Value

Hi Team,
I want to convert below 32 digit number into String Value using Go.

01000111000111111111111100011001

is there any method available for this?

Thanks,
Rajapandian.B

What is the expected result? Which encoding is used?

  • ASCII
  • LATIN-1
  • UTF-8
  • UTF-16-LE
  • UTF-16-BE
  • UTF-32

Same value only. I need 32 digit as String and I will do some split operation.

So you expect this?

"01000111000111111111111100011001"

Yes

How does 01000111000111111111111100011001 enter your system? It is not a valid int. Please show us a code sample that you use to get this number.

Here you go:

package main

import (
	"fmt"
)

func main() {
	i := 1193279257
	s := fmt.Sprintf("\"%b\"", i)
	fmt.Println(s)
}

Output:

"1000111000111111111111100011001"
1 Like

Thanks .It is working.I am trying to prepend β€œ0” at the beginning.I want the below output

β€œ01000111000111111111111100011001”.

i := 1193279257
s := fmt.Sprintf(""%b"", i)
fmt.Println(β€œ0” +s)

But i am getting below output

0"1000111000111111111111100011001"

Thanks,
Rajapandian.B

%032b for binary, 32 digits, zero padded.

Fully documented here: https://golang.org/pkg/fmt/

1 Like

Thanks.But How to call this

fmt.Sprintf("%032b\n", s)

s is having this value -1000111000111111111111100011001 .

i am getting below output

%!b(string=β€œ1000111000111111111111100011001”)

THanks,
Raja

fmt.Sprintf("%032b\n", s) gives you a string. It doesn’t output anything. How are you producing the output?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.