获取某值的具体某位
2015-09-01 16:47
429 查看
获取某值的具体某位
函数:unsigned char get_bit(unsigned char temp, int bit)
获取某值的具体某位。
参数:temp为传入的值,bit是要获取temp的值具体某一位的值
返回值:函数返回 传入参数temp的第bit位的值。
函数:unsigned char get_bit(unsigned char temp, int bit)
获取某值的具体某位。
参数:temp为传入的值,bit是要获取temp的值具体某一位的值
返回值:函数返回 传入参数temp的第bit位的值。
#include <stdio.h> #include <stdlib.h> /************************************************************************/ /*函数:unsigned char get_bit(unsigned char temp, int bit) */ /* 获取某值的具体某位。 */ /*参数:temp为传入的值,bit是要获取temp的值具体某一位的值 */ /*返回值:函数返回 传入参数temp的第bit位的值。 */ /************************************************************************/ unsigned char get_bit(unsigned char temp, int bit) { if ( (bit < 0) || (bit > 8) ) { printf("获取的位值不存在\n"); return -1; } else { return (temp >> bit)&0x01; } } int main(void) { unsigned char temp = 0; int bit = 0; unsigned char getbit = 0; scanf("%d %d", &temp, &bit); getbit = get_bit(temp, bit); // 7 // 0000 0111 printf("bit : %x\n", getbit); system("pause"); }
相关文章推荐
- 第十一届湖南省省赛 - 简单的图论问题?(BFS)
- UIResponder - 1
- 短语out of the blue
- EAX, EBX, ECX, EDX, ESI, EDI, EBP, ESP
- 逆波兰表达式
- HDU2108 Shape of HDU
- codeforces 415E E. Devu and Flowers(组合数学+容斥原理)
- SharePoint Server 2013介绍v2
- 用一个bat方法 快速进入mysql的cmd
- PAT 1075. PAT Judge (25)
- park入门实战系列--6.SparkSQL(下)--Spark实战应用
- #include<list>
- Android笔记(十三)AsyncTask(一)
- mac os x 添加自定义字体库
- handlebars-----另一种help的写法
- 萤石A1互联网报警盒子破解细节分析
- web.xml中的url-pattern映射规则
- 关于squirrel的那些事
- Compress--- The input point cloud
- 浅谈深度学习(Deep Learning)的基本思想和方法