zoukankan      html  css  js  c++  java
  • C实现二进制高低逆序

    方法一:效率低

    int func(unsigned int uiData , int length)
    {
        unsigned int uiValue = 0 ;
        int            i        = 0 ;
        for  ( i = 0 ; i < length ; i++ )  
    {
           uiValue  = (uiValue << 1) + (uiData & 0x01) ;
           uiData   = uiData >> 1 ;
        }
        return uiValue ;
    }

    方法二:分治

    int func (unsigned int uiData)
    {
        unsigned int uiValue = 0 ;
        /* 分而治之的思想 */
        /* 高16位和低16互换 */
        uiValue = ((uiData >> 16)&0x0000ffff) |
    ((uiData << 16)&0xffff0000);
    /*高低16位中的高低8位互换*/
        uiValue = ((uiValue >> 8)&0x00ff00ff) |
    ((uiValue << 8)&0xff00ff00);
    /*8位中的高低4位互换*/
        uiValue = ((uiValue >> 4)&0x0f0f0f0f) |
    ((uiValue << 4)&0xf0f0f0f0);
    /*4位中的高低2位互换*/
        uiValue = ((uiValue >> 2)&0x33333333) |
    ((uiValue << 2)&0xcccccccc);
    /*2位中的高低位互换*/
        uiValue = ((uiValue >> 1)&0x55555555) |
    ((uiValue << 1)&0xaaaaaaaa);
        return uiValue ;
    }
  • 相关阅读:
    工单相关函数
    ABAP 没有保存的长文本,如何取值
    小细节
    DEMO程序 排序
    ABAP 中的消息类型和处理方式
    那些 诡异的表格
    F4搜索帮助~出口函数
    使用XML的方式导出EXCEL
    更改销售订单某些字段和按钮 不可编辑
    ABAP-如何读取内表的字段名称
  • 原文地址:https://www.cnblogs.com/ikaka/p/3355045.html
Copyright © 2011-2022 走看看