1、以QT形式取高八位和低八位

//高八位和低八位
void MainWindow::high_lower_8bit()
{
    quint16 number;
    quint16 right;
    quint16 left;
    quint16 number_three;
    number =32343; //65536个数范围是 -32768-32767       0111 1110(高八位) 0101 0111(低八位)
    right = number&0XFF;//低八位
    left = number>>8;//高八位

    // 前取高八位,在取低八位
    left=(number>>8)&0XFF; //先取高八位
    qDebug()<<"left: "<<left;//0111 1110
    right=number&0XFF;     //再取低八位
    qDebug()<<"right: "<<right;//0101 1111

    // 现在要把高八位和第八位合并
    number_three=left;
    qDebug()<<"number_three1: "<<number_three;//0111 1110
    number_three<<=8;     //左移后赋值
    qDebug()<<"number_three2: "<<number_three;//0111 1110 0000 0000
    number_three|=right;   //按位或后赋值
    qDebug()<<"number_three3: "<<number_three;//0111 1110 0101 0111
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值