golang uint 8 int 8 byte rune変換

8383 ワード

uint8 unsigned 8-bit integers (0 to 255) type byte = uint8 type rune = int32
	b := []byte{'h', 104, 101}	// 
	u8 := []uint8{'h', 104, 101}
	fmt.Printf("%T %T
"
, b, u8) //[]uint8 []uint8 fmt.Println(string(b), string(u8)) // hhe hhe str2 := "hello " data2 := []byte(str2) // fmt.Println(data2) //[104 101 108 108 111 228 184 173 229 155 189] str2 = string(data2) fmt.Println(str2) //hello //int8 :-128~127 var r byte var v int8 v = -70 r = byte(v) // :v<0 256+v;v>0 v fmt.Println("int8->byte: ", r) // var int32_1 int32 = -1 fmt.Printf("%d,%.f", uint32(int32_1), math.Exp2(32)) //4294967295,4294967296 // rune byte rs := []rune{'H', 'e', 'l', 'l', 'o', ' ', ' ', ' '} bs := []byte(string(rs)) fmt.Printf("%s", bs) fmt.Println(string(bs)) rs=[]rune("Hello ") bs=[]byte(string(rs)) fmt.Printf("%s", bs) fmt.Println(string(bs)) // uint8 byte intBs:=[]uint8(bs) fmt.Println(intBs,string(intBs))