问题是:给定一个整数val1找到最高位集(最高有效位)的位置然后,给定第二个整数,val2找到从第一个整数产生的位置左侧的未设置位的连续区域.width指定必须在邻接中找到的最小未设置位数(即width,其中没有一个的零).
这是我的解决方案的C代码:
#include <limits.h> /* for CHAR_BIT - number of bits in a char */
typedef unsigned int t;
unsigned const t_bits = sizeof(t) * CHAR_BIT;
_Bool test_fit_within_left_of_msb( unsigned width,
t val1, /* integer to find MSB of */
t val2, /* integer to find width zero bits in */
unsigned* offset_result)
{
unsigned offbit = 0; /* 0 starts at high bit */
unsigned msb = 0;
t mask; …Run Code Online (Sandbox Code Playgroud)