📄 bitroutines.c
字号:
/* | | Copyright disclaimer: | This software was developed at the National Institute of Standards | and Technology by employees of the Federal Government in the course | of their official duties. Pursuant to title 17 Section 105 of the | United States Code this software is not subject to copyright | protection and is in the public domain. | | We would appreciate acknowledgement if the software is used. |*//* | Project: WCDMA simulation environment | Module: Bit manipulation routines | Author: Tommi Makelainen, NIST | Date: January 6, 1999 | | History: | January 6, 1999 Tommi Makelainen | Initial version. | */#include "bitroutines.h"/* -------------------------------------------------------------------- *//* * Function: extract_bit_from_byte * Desc.: Extract given single bit value from a given byte. * * Inputs: * byte input byte * pos bit position (7-0) 7 = leftmost, 0 = bit on the right * Returns: * bit value (0 or 1) * * Note: */char extract_bit_from_byte(char byte, int pos){ int i; char bit; bit = 0; bit = (byte >> pos) & 0x1; return (bit);}/* -------------------------------------------------------------------- *//* * Function: set_bit_in_byte * Desc.: Set a value of a single bit 'bit' in given * position 'pos' in a byte 'byte'. * * Inputs: * bit input bit value * pos bit position to set * Outputs: * byte modified byte * * Note: */int set_bit_in_byte(char bit, int pos, char *byte){ char temp_byte; temp_byte = 0; temp_byte = (bit << pos); *byte |= temp_byte; return(0);}/* -------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -