🌐
GitHub
github.com › go-goracle › goracle › issues › 103
How to convert goracle.Number to int64 to int32 · Issue #103 · go-goracle/goracle
How to convert goracle.Number to int64 to int32#103 · Copy link · ghost · opened · on Sep 26, 2018 · I'm trying convert a goracle.Number to int64 but return this message: interface conversion: driver.Value is goracle.Number, not int64 · Reactions are currently unavailable ·
Author   ghost
🌐
Google Groups
groups.google.com › g › golang-nuts › c › 7yGYsdFTkWk
Convert int to int32 or int64
I know you can convert int to int64 by doing int64(int). Thanks in advance. ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... I'm not sure I understand the question. You seem to know the answer? ... -- You received this message because you are subscribed to the Google Groups "golang...
Discussions

Converting int32 to uint64 and back to int32
If your input is always int32, then you won't run into issues with converting between the 2. If your input is int64 you will definitely run into issues at some point. So, ensure your codepaths don't allow for user input of the wrong precision. More on reddit.com
🌐 r/golang
16
4
February 5, 2023
time.Unix() int64 to int32 wrong conversion of after "2038-01-19"
What version of Go are you using (go version)? $ go version 1.13.1 Does this issue reproduce with the latest release? yes What operating system and processor architecture are you using (go env)? ht... More on github.com
🌐 github.com
1
December 5, 2019
How to convert an int64 to int in Go? - Stack Overflow
In Go, what is the best strategy for converting int64 to int? I am having difficulty comparing the two package main import ( "math" "strings" "strconv" ) type largestPrimeFactor str... More on stackoverflow.com
🌐 stackoverflow.com
Using int32 for efficiency or simply stick to int64?
Premature optimization. Unless, which I doubt, you determined that there is a performance problem in your application, identified the bottleneck, benchmarked it and compared it with the updated int32 code. Like you've already determined, it takes extra effort to make everything work with int32, especially when interfacing with the stdlib or other libraries. Unless it's really needed, I'd spend that effort on features and other improvements. More on reddit.com
🌐 r/golang
45
52
January 30, 2022
🌐
Go language Tutorial
golangtutorial.dev › home › tips › how to convert an int32 & int64 to string in go
How to Convert an int32 & int64 to string in Go - Go language Tutorial
November 5, 2020 - var n int64 = 100 hexaDecimal := strconv.FormatInt(n, 16) fmt.Printf("%T, %v\n",hexaDecimal,hexaDecimal) output: string, 64 · Even we can use strconv.FormatInt to convert int32 to string.
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › how to change int to int64 in golang? [solved]
How to change int to int64 in Golang? [SOLVED] | GoLinuxCloud
January 8, 2023 - In Golang, it is very simple to convert an int to int64. In today's post, we will show you some simple examples of converting an int to int64. Depending on the platform, an int can be either 32 or 64 bits. Normally, an index, length, or capacity should be an int. The optimal data types are int8, int16, int32...
🌐
Reddit
reddit.com › r/golang › converting int32 to uint64 and back to int32
r/golang on Reddit: Converting int32 to uint64 and back to int32
February 5, 2023 -

I am a bit concerned about a piece of code I wrote. It seems to work but I did not quite expect it to...

How does type conversion exactly work in Go when I convert a int32 to uint64 and then back to int32. I was somewhat scared that funny business might happen.

To give practical context of what I am doing. I have data like:

type data struct {
    a uint16
    b uint8
    c uint8
    d int32
}

Instead of using a data struct I want to package all the values in a single uint64 like:

data := uint64(a) | uint64(b)<<16 | uint64(c)<<24 | uint64(d)<<32

and then unpack it like (shifting back and applying a bit mask if necessary):

d := int32(data>>32)

my worries were around:

data = uint64(int32(d))

I was worried that it would try to do some conversion from int32 with negative values. But running some tests all it seems to be doing is padding or truncating bits and interpreting the two's compliment int values as uint.

Is this all safe and correct or am I about to run into nightmarish bugs?

Edit: In essence what I am asking with go type conversions does this hold for every value of d of type int32 :

d == int32(uint64(d))

🌐
GitHub
github.com › golang › go › issues › 35991
time.Unix() int64 to int32 wrong conversion of after "2038-01-19" · Issue #35991 · golang/go
December 5, 2019 - val := "2038-01-20" ts, _ := time.Parse("2006-01-02", val) fmt.Println((ts.Unix())) fmt.Println(int32(ts.Unix()), " <--") // problem with conversion val = "2038-01-19" ts, _ = time.Parse("2006-01-02", val) fmt.Println((ts.Unix())) fmt.Println(int32(ts.Unix()))
Author   eldadts
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-convert-data-types-in-go
How To Convert Data Types in Go | DigitalOcean
May 9, 2019 - Outputindex data type: int8 bigIndex ... the converted data type. You can also convert from a larger bit-size integer to a smaller bit-size integer: var big int64 = 64 var little int8 little = int8(big) fmt.Println(little)...
🌐
Medium
irshadhasmat.medium.com › golang-string-to-int-int64-conversion-and-int-int64-to-string-conversion-774f9f23cb03
GoLang : String to Int & Int64 Conversion and Int & int64 to String Conversion | by Mohammed Irshad | Medium
June 15, 2018 - Conversion of datatype is a normal task of every developer. So, here I would be giving you a snippet of how to convert string to int and int64 and vice versa.
Find elsewhere
🌐
Go Packages
pkg.go.dev › github.com › reiver › go-cast
cast package - github.com/reiver/go-cast - Go Packages
August 10, 2025 - Int32Else is similar to Int32 except that if a cast cannot be done, it returns the `alternative`. ... Int64 will return an int64 when `v` is of type int64, int32, int16, int8, int, uint32, uint16, uint8 or has a method:
🌐
Reddit
reddit.com › r/golang › using int32 for efficiency or simply stick to int64?
r/golang on Reddit: Using int32 for efficiency or simply stick to int64?
January 30, 2022 -

I have a field in my data which is small enough to simply use an int32. However, from what I can tell, int32 is generally used when representing a code point or something quite specific, rather than using it simply to save 32 bits of storage. Also, some of the stdlib packages (like strconv) deal exclusively with int64 rather than int32. This has meant changes to my code I didn't expect purely to handle int32 things.

What is your opinion (and perhaps the general consensus) on using int32 purely for efficiency purposes? Is it just worth using an int64 for simplicity?

🌐
Google Groups
groups.google.com › g › golang-nuts › c › 7pZyAfleHok
Type Assertion Panic on Int32 and Int64
So int32 to int32. > But due to this issue, I have to either change my struct to int and then > assert into int or I can keep my struct variable int32, type assert as int > and then cast as int32. > > All I want to understand is why I can't type assert as int32 or int64?
🌐
gosamples
gosamples.dev › tutorials › convert int to string in go
🔢 Convert int to string in Go
July 23, 2021 - var number int64 = 12 // int, int32, int16, int8 str := strconv.FormatInt(number, 2) fmt.Println(str)
Top answer
1 of 6
78
func ParseInt(s string, base int, bitSize int) (i int64, err error)

ParseInt always returns int64.

bitSize defines the range of values.

If the value corresponding to s cannot be represented by a signed integer of the given size, err.Err = ErrRange.

http://golang.org/pkg/strconv/#ParseInt

type int int

int is a signed integer type that is at least 32 bits in size. It is a distinct type, however, and not an alias for, say, int32.

http://golang.org/pkg/builtin/#int

So int could be bigger than 32 bit in the future or on some systems like int in C.

I guess on some systems int64 might be faster than int32 because that system only works with 64-bit integers.

Here is an example of an error when bitSize is 8:

http://play.golang.org/p/_osjMqL6Nj

package main

import (
    "fmt"
    "strconv"
)

func main() {
    i, err := strconv.ParseInt("123456", 10, 8)
    fmt.Println(i, err)
}
2 of 6
36

Package strconv

func ParseInt

func ParseInt(s string, base int, bitSize int) (i int64, err error)

ParseInt interprets a string s in the given base (2 to 36) and returns the corresponding value i. If base == 0, the base is implied by the string's prefix: base 16 for "0x", base 8 for "0", and base 10 otherwise.

The bitSize argument specifies the integer type that the result must fit into. Bit sizes 0, 8, 16, 32, and 64 correspond to int, int8, int16, int32, and int64.

The errors that ParseInt returns have concrete type *NumError and include err.Num = s. If s is empty or contains invalid digits, err.Err = ErrSyntax; if the value corresponding to s cannot be represented by a signed integer of the given size, err.Err = ErrRange.

ParseInt always returns an int64 value. Depending on bitSize, this value will fit into int, int8, int16, int32, or int64. If the value cannot be represented by a signed integer of the size given by bitSize, then err.Err = ErrRange.

The Go Programming Language Specification

Numeric types

The value of an n-bit integer is n bits wide and represented using two's complement arithmetic.

int8        the set of all signed  8-bit integers (-128 to 127)
int16       the set of all signed 16-bit integers (-32768 to 32767)
int32       the set of all signed 32-bit integers (-2147483648 to 2147483647)
int64       the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)

There is also a set of predeclared numeric types with implementation-specific sizes:

uint     either 32 or 64 bits
int      same size as uint

int is either 32 or 64 bits, depending on the implementation. Usually it's 32 bits for 32-bit compilers and 64 bits for 64-bit compilers.

To find out the size of an int or uint, use strconv.IntSize.

Package strconv

Constants

const IntSize = intSize

IntSize is the size in bits of an int or uint value.

For example,

package main

import (
    "fmt"
    "runtime"
    "strconv"
)

func main() {
    fmt.Println(runtime.Compiler, runtime.GOARCH, runtime.GOOS)
    fmt.Println(strconv.IntSize)
}

Output:

gc amd64 linux
64
🌐
YourBasic
yourbasic.org › golang › int-vs-int64
Pick the right one: int vs. int64 · YourBasic Go
An int64 is the typical choice when memory isn’t an issue. In particular, you can use a byte, which is an alias for uint8, to be extra clear about your intent. Similarly, you can use a rune, which is an alias for int32, to emphasize than an integer represents a code point.
🌐
Hyperskill
hyperskill.org › learn › step › 18710
Type conversion and overflow
Hyperskill is an educational platform for learning programming and software development through project-based courses, that helps you secure a job in tech. Master Python, Java, Kotlin, and more with real-world coding challenges.
🌐
Educative
educative.io › answers › what-is-type-int64-in-golang
What is type int64 in Golang?
int is one of the available numeric data types in Go used to store signed integers. int64 is a version of int that only stores signed numeric values composed of up to 64 bits.