Converting uint to string

928 views
Skip to first unread message

Chun Zhang

unread,
Nov 5, 2017, 4:08:56 PM11/5/17
to golang-nuts
Hi, All, 

I have a group of integers ranging from 1 to 2^32 that are in the format of uint32. I know strconv.Itoa(i) or strconv.FormatUint(i) can definitely give unique representation of each number. So, I can use it as the index of a map[string]interface{}.

However, I am wondering if I use string(i) only, will I get any two numbers the same string representation? My guess is no, but would like to get some comments from you experts.

Also, will string(i) be faster than strconv.Itoa or strcov.FormatUInt?



Thanks,
Chun


Jan Mercl

unread,
Nov 5, 2017, 4:17:43 PM11/5/17
to Chun Zhang, golang-nuts
On Sun, Nov 5, 2017 at 10:09 PM Chun Zhang <chun...@gmail.com> wrote:

> I have a group of integers ranging from 1 to 2^32 that are in the format of uint32.

Assuming you mean 'to 2^32-1'.

> However, I am wondering if I use string(i) only, will I get any two numbers the same string representation? My guess is no, but would like to get some comments from you experts.

--

-j

Chun Zhang

unread,
Nov 5, 2017, 4:39:08 PM11/5/17
to golang-nuts
Hi, Jan, 

Thank you very much!!

Best,
Chun

John Souvestre

unread,
Nov 5, 2017, 4:55:46 PM11/5/17
to golan...@googlegroups.com

You could also just the integers themselves as keys.

 

John

    John Souvestre - New Orleans LA

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages