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);
}