简单位操作(NVIDIA)
2012-09-24 14:56
141 查看
#include "stdafx.h" #include <stdio.h> #include <iostream> #include <stdlib.h> #include <math.h> using namespace std; /********************************************************************* NVIDIA 2013 Software Engineering Campus Recruitment Exam Test Paper SH-01-A-Arch&Content 4. Please implement a funciton to only modify partial bits of a 32-bit unsigned integer variable. The prototype of the function is as follows: void modify(uint_32 &var, uint_8 bit_high, unit_8 bit_low, uint_32 value); Example: unit_32 register = 0xbed; modify(register,7,4,0xa); // register = 0xbad **********************************************************************/ typedef unsigned int uint_32; typedef unsigned int uint_8; void modify(uint_32 &var, uint_8 bit_high, uint_8 bit_low, uint_32 value) { int i = 0; int j =0; // clear or reset the corresponding bits for(i = bit_low;i<=bit_high;i++) { var &=~(0x01<<i); } // set the corresponding bits for(i = bit_low;i<=bit_high;i++) { j = value & 0x01; var |=((value&0x01)<<i); value =value>> 1; } } int _tmain(int argc, _TCHAR* argv[]) { uint_32 register0 = 0xbed; modify(register0, 3, 0, 0xa); printf("the Modify result is %x\n",register0); return 0; }
// 运行结果
相关文章推荐
- Ubuntu最简单的方式安装NVIDIA显卡驱动和cuda工具
- ubuntu下简单安装beryl特效(nvidia)
- 你必须知道的简单的位操作技巧
- 总结:如何用位操作来简单有效的解决问题
- ubuntu16.04安装NVIDIA显卡驱动 使用ppa简单快捷安装
- NVIDIA_Fermi_GPU架构简单解析(转)
- (翻译整理)如何简单、高效地使用位操作解决问题
- 简单点亮发光二极管实例(位操作)
- 利用位操作实现简单的功能
- 九度OJ 1197:奇偶校验 简单的位操作习题
- 简单的位操作
- NVIDIA芯片组BIOS设置和RAID设置简单介绍
- ubuntu16.04安装NVIDIA驱动最简单的方法
- NVIDIA Fermi GPU架构简单解析
- java 简单的位操作
- 简单的位操作
- asp中用CDO发送简单电子邮件
- 简单获取键盘的KeyCode
- socket编程简单思路
- 最简单的隐藏文件夹方法