This is a creation in Article, where the information may have evolved or changed.
Golang is a strongly typed language, which is used in the basic type conversion process. Here's a look at the common type conversions, which are constantly updated.
Shaping A string
Fmt. Println (StrConv. Itoa (100))
The source code for this method is:
Itoa is shorthand for formatint (I, ten). Func Itoa (i int) string {return Formatint (Int64 (i), 10)}
Can be seen is a simple implementation of the Formatint method.
String to reshape
I, _: = StrConv. Atoi ("+") fmt. Println (i)
64-bit shaping of the turn string
var i int64i = 0x100fmt. Println (StrConv. Formatint (i, 10))
Formatint The second parameter represents the binary, and 10 represents the decimal.
BYTE-to-32-bit shaping
B: = []byte{0x00, 0x00, 0x03, 0xe8}bytesbuffer: = bytes. Newbuffer (b) var x int32binary. Read (Bytesbuffer, Binary. Bigendian, &x) fmt. PRINTLN (x)
where binary. The Bigendian represents the byte order, and the corresponding little endian. Popular parlance is called big-endian, small end.
32-bit shaping of the turn byte
var x int32x = 106bytesBuffer: = bytes. Newbuffer ([]byte{}) binary. Write (Bytesbuffer, Binary. Bigendian, X) fmt. Println (Bytesbuffer.bytes ())
byte-to-string
Fmt. Println (String ([]byte{97, 98, 99, 100})
String to Byte
Fmt. Println ([]byte ("ABCD"))