Sitemap
Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Member-only story

Go Types Explained: Why Numbers Need Conversion and Strings Count Bytes

--

A practical guide to integer conversions, floating-point precision, and the difference between bytes, runes, and characters.

Press enter or click to view image in full size

Not a member? Read it here.

A number looks like a number. A string looks like text. Then you start learning Go, and two small examples challenge those assumptions.

Assigning an int16 variable to an int32 variable fails to compile. Calling len("čau") returns 4, even though you can see three letters.

💡 Fun fact: “Čau” means “hi” in Czech — and you can also use it to say “bye.” Three letters, four bytes in UTF-8, and two meanings. Pretty efficient for such a small word!

Both results become predictable once you understand how Go represents values. These details matter when you move beyond tutorial inputs and start handling numeric boundaries, international names, and real application data.

The snippets below belong inside a main function. Examples using fmt or utf8 require imports for fmt or unicode/utf8, respectively.

Why Go asks you to convert numbers explicitly

Consider two integer variables:

var small int16 = 42
var large int32

// large = small // Compile error
large…

--

--

Tomas Svojanovsky
Tomas Svojanovsky

Written by Tomas Svojanovsky

I'm a full-stack developer. Programming isn't just my job but also my hobby. I like developing seamless user experiences and working on server-side complexities

Dev Genius
Dev Genius

Published in Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development