日常生活的交流与学习

首页 新随笔 联系 管理
package main

import (
"fmt"
)
type Bytes[]byte

func main(){
	fmt.Println("hello") 
	fmt.Println("--------------")
	// ascii 字符====================================
	var ascChar = Bytes{65}
	fmt.Println(string(ascChar))
	fmt.Println(len(ascChar))
	fmt.Println("--------------")
	// 十六进制======================================
	var u8 = 0x41
	fmt.Printf("%d\n", u8)
	fmt.Printf("0x%x\n", u8)
	fmt.Println("--------------")
	
	// 取高八位和低八位==================================
	var reqId uint16 = 2002 
	// ----high 8 bit
	reqIdH := uint8(reqId>>8)
	fmt.Printf("reqIdH = 0x%x\n",reqIdH)
	fmt.Printf("type of reqIdH = %T\n",reqIdH)
	// ----low 8 bit
	reqIdL := uint8(reqId &0xff )
	fmt.Printf("reqIdL = 0x%x\n",reqIdL)
	fmt.Printf("type of reqIdL = %T\n",reqIdL)
	fmt.Println("--------------")
	// msgLen============================
	var msgLen uint32 = 0x12345678
	var msgLenHH uint8 = uint8(msgLen >> 24 )
	var msgLenHL uint8=uint8(msgLen >> 16 & 0xff )
	var msgLenLH uint8=uint8(msgLen >> 8 & 0xff )
	var msgLenLL uint8=uint8(msgLen  & 0xff )

	fmt.Printf("msgLenHH = 0x%x\n",msgLenHH)
	fmt.Printf("type of msgLenHH = %T\n",msgLenHH)

	fmt.Printf("msgLenHL = 0x%x\n",msgLenHL)
	fmt.Printf("type of msgLenHL = %T\n",msgLenHH)

	fmt.Printf("msgLenLH = 0x%x\n",msgLenLH)
	fmt.Printf("type of msgLenLH = %T\n",msgLenHH)

	fmt.Printf("msgLenLL = 0x%x\n",msgLenLL)
	fmt.Printf("type of msgLenLL = %T\n",msgLenHH)
	fmt.Println("--------------")
	// msgType =======================
	var msgType uint16 = 0x1234 
	// ----high 8 bit
	msgTypeH := uint8(msgType>>8)
	fmt.Printf("msgTypeH = 0x%x\n",msgTypeH)
	fmt.Printf("type of msgTypeH = %T\n",msgTypeH)
	// ----low 8 bit
	msgTypeL := uint8(msgType &0xff )
	fmt.Printf("msgTypeL = 0x%x\n",msgTypeL)
	fmt.Printf("type of msgTypeL = %T\n",msgTypeL)
	fmt.Println("--------------")

// agv 报文结构======================================
	agvTcp := Bytes{0x5A,0x01,reqIdH,reqIdL,msgLenHH,msgLenHL,msgLenLH,msgLenLL,msgTypeH,msgTypeL}
	fmt.Printf("%x\n",agvTcp)
	fmt.Println("--------------")


















	





	





}
posted on 2022-12-01 19:27  lazycookie  阅读(178)  评论(0编辑  收藏  举报