20155204 《信息安全系统设计》1.3课上作业总结

1.3课上作业总结

课上代码

#define base 0xFFFFC000
#define &time base+2 

void setHour(int hours){
    time = time & 0x07FF;
    time = (hours << 11)|time;
}

int getHours(){
    return ((int)(time>>11) & 0x001F);
}

理解

  • setHours:首先将time的前五位,也即hours位置0,然后将hours通过或操作添加到time里。
  • getHours:将time右移11位跟0x001F与,得到hours值。

延伸(提取秒)

#define base 0xFFFFC000
#define &time base+2 

void setSecond(int second){
    time = time & 0xFFF0;
    time = second|time;
}

int getSecond(){
    return ((int)time & 0x000F);
} 
posted @ 2018-01-03 10:22  20155204王昊  阅读(101)  评论(0编辑  收藏  举报