码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-06-09 01:00:50      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:printf      

#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

标签:printf      

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!