Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert uint32 to string?

Tags:

go

I need to convert an uint32 to string. How can I do that? strconv.Itoa doesn't seem to work.

Long story:
I need to convert an UID received through the imap package to string so that I can set it later as a sequence. As a side note I'm wondering why such conversions are difficult in Go. A cast string(t) could have been so much easier.

like image 654
hey Avatar asked Jul 22 '14 11:07

hey


People also ask

What is UInt32?

The UInt32 value type represents unsigned integers with values ranging from 0 to 4,294,967,295. UInt32 provides methods to compare instances of this type, convert the value of an instance to its String representation, and convert the String representation of a number to an instance of this type.


1 Answers

I would do this using strconv.FormatUint:

import "strconv"  var u uint32 = 17 var s = strconv.FormatUint(uint64(u), 10) // "17" 

Note that the expected parameter is uint64, so you have to cast your uint32 first. There is no specific FormatUint32 function.

like image 57
julienc Avatar answered Oct 14 '22 11:10

julienc