You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
974 B

3 years ago
package main
import (
"encoding/hex"
"fmt"
)
func main() {
fmt.Println("\n ================== 基础类型 = 开始 ================== ")
boolvar := true
fmt.Println("布尔\t boolvar = ", boolvar)
var intvar int
fmt.Println("整形\t intvar = ", intvar)
var float32var float32
fmt.Println("浮点型\t float32var = ", float32var)
var bytevar byte
bytevar = 'a'
fmt.Println("字符\t bytevar = ", bytevar)
var int32 byte
int32 = 0x31
//int32 = int32+1
fmt.Println("16进制数值\t int32 = ", int32)
// 注意"Hello"与"encodedStr"不相等,encodedStr是用字符串来表示16进制
src := []byte("Hello")
// [72 101 108 108 111]
fmt.Println("16进制Hex\t src = ", src)
// 48656c6c6f -> 48(4*16+8=72) 65(6*16+5=101) 6c 6c 6f
encodedStr := hex.EncodeToString(src)
fmt.Println("16进制Hex\t encodedStr = ", encodedStr)
intcodedStr := hex.EncodeToString([]byte("192.168.1.123"))
fmt.Println("16进制Hex\t intcodedStr = ", intcodedStr)
}