HDLC协议的目的地址域源地址

对报文进行验证,得知四字节目的地址的地址的范围为0~16383

#include <stdio.h>
#include <stdint.h>
//目的地址,验证程序
int main() {
    // 定义U8类型的数组

    //为什么广播地址是0x3FFF 3FFF,而不是FFFF FFFF,因为实际使用的地址位是32-4=28位,每个字节的最低位用来扩展编址了,实际没有用到
    uint8_t u8Array[4] = { 0xFE, 0xFE, 0xFE, 0xFE, };       //0x3FFF 3FFF
    //uint8_t u8Array[4] = { 0x00, 0x02, 0xC0, 0x01, };     //0X0001 30000
    uint8_t* pucServerAddrPt = (uint8_t*)u8Array;
    uint16_t  us_lgc_HDLC_addr;
    us_lgc_HDLC_addr = *pucServerAddrPt;		//00		0000 0000
    us_lgc_HDLC_addr <<= 7;		//0000 0000 0000 000
    us_lgc_HDLC_addr += *(pucServerAddrPt + 1);	//+0000 0010=0000 0000 0000 010
    us_lgc_HDLC_addr >>= 1;		//0000 0000 0000 01

    printf("高HDLC地址:0x%X\n", us_lgc_HDLC_addr);

    //低HDLC地址
    us_lgc_HDLC_addr = 0;
    us_lgc_HDLC_addr = *(pucServerAddrPt+2);		//00		0000 0000
    us_lgc_HDLC_addr <<= 7;		//0000 0000 0000 000
    us_lgc_HDLC_addr += *(pucServerAddrPt + 3);	//+0000 0010=0000 0000 0000 010
    us_lgc_HDLC_addr >>= 1;		//0000 0000 0000 01
    printf("低HDLC地址:0x%X\n", us_lgc_HDLC_addr);
    
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值