📄 bitfield.c
字号:
/*********************************************************************** Copyright (c) 2002 RADVISION Ltd.************************************************************************NOTICE:This document contains information that is confidential and proprietaryto RADVISION Ltd.. No part of this document may be reproduced in anyform whatsoever without written prior approval by RADVISION Ltd..RADVISION Ltd. reserve the right to revise this publication and makechanges without obligation to notify any person of such revisions orchanges.***********************************************************************//**************************************************************************** bitfield.c -- Bit-field manipulation Abstract: Misc. routines for bit field manipulation.****************************************************************************/#include "bitfield.h"#ifdef __cplusplusextern "C" {#endif/*===========================================================================** == bitfieldSet() == **** **** Sets a sequence of bits in an integer to a specified value. **** **** PARAMETERS: **** value The integer value to work on. **** **** bitfield The bit sequence to insert into the integer. **** **** nStartBit This value specifies the list-segnificant bit index **** for the bit sequence. e.g. if nStartBit is set to 1, **** and nBits is set to 3, the bit sequence will occupy **** bits 1 through 4. **** **** nBits The number of bits in the bit sequence. **** **** RETURNS: **** The new integer value. **** ****=========================================================================*/RvUint32 bitfieldSet( IN RvUint32 value, IN RvUint32 bitfield, IN int nStartBit, IN int nBits){ int mask = (1 << nBits) - 1; return (value & ~(mask << nStartBit)) + ((bitfield & mask) << nStartBit);}/*===========================================================================** == bitfieldGet() == **** **** Retreives the sequence of bits in an integer. **** **** PARAMETERS: **** value The integer value to work on. **** **** nStartBit This value specifies the list-segnificant bit index **** of the bit sequence. e.g. if nStartBit is set to 1, **** and nBits is set to 3, the bit sequence in bits 1 **** through 4 is used. **** **** nBits The number of bits in the bit sequence. **** **** RETURNS: **** Returns the bit sequence. The sequence will occupy bits **** 0..(Bits-1). **** ****=========================================================================*/RvUint32 bitfieldGet( IN RvUint32 value, IN int nStartBit, IN int nBits){ int mask = (1 << nBits) - 1; return (value >> nStartBit) & mask;}#ifdef __cplusplus}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -