首页 > 其他 > 详细

实现一个对8bit数据指定某一位置0或1

时间:2015-06-09 00:59:50      阅读:506      评论:0      收藏:0      [点我收藏+]
#include<stdio.h>

void bit_set(unsigned char *p_date, unsigned char position, int flag)
{
	if (flag == 1)
	{
		*p_date |= (1 << (position - 1));//0000 0010或0000 0001
	}                                   // 0000 0011
	else if (flag = 0)
	{
		*p_date &= ~(1 << (position - 1));//0000 0010&1111 1110
	}                                    // 0000 0010
	
}

int main()
{
	unsigned char val = 2;
	bit_set(&val, 1, 0);
	printf("%d\n", val);
	getchar();
	return 0;
}

实现一个对8bit数据指定某一位置0或1

原文:http://blog.csdn.net/yangrujing/article/details/46419637

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!