• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ setbits函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中setbits函数的典型用法代码示例。如果您正苦于以下问题:C++ setbits函数的具体用法?C++ setbits怎么用?C++ setbits使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了setbits函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: matrix_scan_user

void matrix_scan_user(void) {
  //
  // Bit #            7     6     5     4     3     2     1     0
  // layer_state: [     |     |     | _xF | _xN | _xS | _xQ | _xW ]
  // usb_led      [     |     |     |kana |cmps |scrl |caps | num ]
  // PORTB:       [  NC |  10 |   9 |   8 |  14 |  16 |  15 |rxled]
  // PORTC:       [  NC |   5 |     |     |     |     |     |     ]
  // PORTD:       [   6 |  NC |txled|   4 | tx* | rx* | grn | p29 ]
  // PORTE:       [     |   7 |     |     |     |     |     |     ]
  // PORTF:       [  a0 |  a1 | red | blu |     |     |  NC |  NC ]
  //
  // PD0 is connected to the pairing switch and p29 on the wireless module.
  // PF0,PF1,PB7,PC7,PD6 are not broken out by the pro micro board. I don't understand why.
  // PB1-PB6,PD4,PD5,PD6,PF6,PF7 are not connected to the Mitosis receiver
  // board. Each may be connected to an LED by way of a resistor (4.7k to
  // match the others) for a total of 14 additional indicators.

  // A simple (but technically inaccurate) model of the momentary layer state:
  // Fn1 key makes _xS active; indicator = red
  // Fn2 key makes _xN active; indicator = blue
  // Both keys make _xF active; indicator = purple
  // Toggling QWERTY mode makes indicator include green, so (red/blue/purple becomes yellow/cyan/white)

  // negated because for ports 0=LED on.
  uint32_t portf_bits = ~(layer_state|layer_state<<1|(layer_state&0b100)<<3);
  setbits(PORTF, portf_bits, 0b00110000);
  setbits(PORTD, ~layer_state, 0b00000010);
}
开发者ID:WillMoggridge,项目名称:qmk_firmware,代码行数:28,代码来源:keymap.c


示例2: main

void main(char args[]){

	//x = 1001101 (77)  y = 1000111  (71)
	//P = 5 N = 4
	//1[0011]01 in x
	//100[0111] in y
	//Want -> 1011101 (93)
	printf("%u\n", setbits(77, 5, 4, 71)); 
	
	//x = 10110 (22) y = 11111 (32)
	//P = 3 N = 1 
	//1[0]110  in x
	//1111[1] in y
	//Want -> 11110 (30)	
	printf("%u\n", setbits(22, 3, 1, 31));
	
	//x = 11 (3) y = 111100 (60)
	//P = 1 N = 2
	//[11] in x
	//1111[00] in y
	//Want -> 00 (0)
	printf("%u\n", setbits(3,1,2,60));
	
	//x = 1110 (14) y = 1101 (13)
	//P = 2 N = 2
	//1[11]0 in x
	//11[01] in y
	//Want -> 1010 (10)
	printf("%u\n", setbits(14,2,2,13));
}
开发者ID:track02,项目名称:KRC_Workthrough,代码行数:30,代码来源:2.6.c


示例3: MemClrNoLog

void MemClrNoLog ( UINT32 addr,       //Memory Address
				   int total_byte,    //Number of Data to clear in Byte
				   UINT32 logaddr, 
				   int logbit                                        
				 )
{
	UINT32 result;
	int i,j=0;	

	for(i=0;i<total_byte;i=i+4)
	{
		set32(addr+(UINT32)i,0x0);
		result = read32(addr+(UINT32)i);
		if(result == 0x0)
		{ 
			j++; 
		}
		else
		{ 
			j=j; 
		}
	}
	if(j == total_byte/4)
	{
		setbits(logaddr, logbit, logbit, 1);
	}
	else
	{
		setbits(logaddr, logbit, logbit, 0);
	}

	return;
}
开发者ID:debbiche,项目名称:android_kernel_huawei_p8,代码行数:33,代码来源:mem_fun.c


示例4: main

int main() {
  assert(setbits(0xff, 3, 4, 0xaa) == 0xfa);
  /* wrong input */
  assert(setbits(0xff, 0, 4, 0xaa) == 0xff);
  assert(setbits(0xff, 0, 1, 0xaa) == 0xfe);
  assert(setbits(0xff, 3, 0, 0xaa) == 0xff);
  return 0;
}
开发者ID:B-Rich,项目名称:the_c_programming_language,代码行数:8,代码来源:0206.c


示例5: main

int main(int argc, char const* argv[])
{
  setbits(1, 0, 1, 1);
  setbits(1, 1, 2, 1);
  setbits(1, 2, 3, 1);
  setbits(1, 3, 4, 1);
  setbits(1, 4, 5, 1);
  return 0;
}
开发者ID:dannas,项目名称:c_programming_language,代码行数:9,代码来源:ex_2_6.c


示例6: r8a66597_clock_enable

static int r8a66597_clock_enable(struct r8a66597 *r8a66597)
{
	u16 tmp;
	int i = 0;

#if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
	do {
		r8a66597_write(r8a66597, SCKE, SYSCFG0);
		tmp = r8a66597_read(r8a66597, SYSCFG0);
		if (i++ > 1000) {
			printf("register access fail.\n");
			return -1;
		}
	} while ((tmp & SCKE) != SCKE);
	r8a66597_write(r8a66597, 0x04, 0x02);
#else
	do {
		r8a66597_write(r8a66597, USBE, SYSCFG0);
		tmp = r8a66597_read(r8a66597, SYSCFG0);
		if (i++ > 1000) {
			printf("register access fail.\n");
			return -1;
		}
	} while ((tmp & USBE) != USBE);
	r8a66597_bclr(r8a66597, USBE, SYSCFG0);
#if !defined(CONFIG_RZA_USB)
	r8a66597_mdfy(r8a66597, CONFIG_R8A66597_XTAL, XTAL, SYSCFG0);

	i = 0;
	r8a66597_bset(r8a66597, XCKE, SYSCFG0);
	do {
		udelay(1000);
		tmp = r8a66597_read(r8a66597, SYSCFG0);
		if (i++ > 500) {
			printf("register access fail.\n");
			return -1;
		}
	} while ((tmp & SCKE) != SCKE);
#else
	/*
	 * RZ/A Only:
	 * Bits XTAL(UCKSEL) and UPLLE in SYSCFG0 for USB0 controls both USB0
	 * and USB1, so we must always set the USB0 register
	 */
#if (CONFIG_R8A66597_XTAL == 1)
	setbits(le16, R8A66597_BASE0, XTAL);
#endif
	mdelay(1);
	setbits(le16, R8A66597_BASE0, UPLLE);
	mdelay(1);
	r8a66597_bset(r8a66597, SUSPM, SUSPMODE0);
#endif /* CONFIG_RZA_USB */
#endif	/* #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) */

	return 0;
}
开发者ID:krtkl,项目名称:snickerdoodle-u-boot,代码行数:56,代码来源:r8a66597-hcd.c


示例7: encode_number

int encode_number(char *msg, char *no) {
	unsigned int i;
	int digit;
	
	setbits(msg, 0, 2, 0);
	setbits(msg, 2, 8, strlen(no));
	for(i=0;i<strlen(no);i++)
		setbits(msg,10+i*4, 4, encode_digit(no[i]));
	return (10+i*4+7)/8;
}
开发者ID:checko,项目名称:sxx-ril,代码行数:10,代码来源:sms.c


示例8: main

int main() {
  if (n % 2 == 0) {
    backtracking(setbits(n/2), 0, 0, 0, 0);
    std::cout << 2*count << " " << nodes << "\n";
  }
  else {
    backtracking(setbits(n/2), 0, 0, 0, 0);
    const count_t half = count; count = 0;
    backtracking(queen_t().set(n/2), 0, 0, 0, 0);
    std::cout << 2*half + count << " " << nodes << "\n";
  }
}
开发者ID:MHenderson,项目名称:oklibrary,代码行数:12,代码来源:NQueens_ct.cpp


示例9: setbits

// initialize LCD after a short pause
//while there are hard-coded details here of lines, cursor and blink settings, you can override these original settings after calling .init()
void LCD4Bit_mod::init() {
  // Configure pins as outputs
  setbits(CONTROL_DDR, CONTROL_EN | CONTROL_RS);
#ifdef USING_RW
  setbits(CONTROL_DDR, CONTROL_RW);
#endif
  setbits(DATA_DDR, DATA_PINS);

  delay(50);

  //The first 4 nibbles and timings are not in my DEM16217 SYH datasheet, but apparently are HD44780 standard...
  commandWriteNibble(0x03);
  delay(5);
  commandWriteNibble(0x03);
  delayMicroseconds(100);
  commandWriteNibble(0x03);
  delay(5);

  // needed by the LCDs controller
  //this being 2 sets up 4-bit mode.
  commandWriteNibble(0x02);
  commandWriteNibble(0x02);
  //todo: make configurable by the user of this library.
  //NFXX where
  //N = num lines (0=1 line or 1=2 lines).
  //F= format (number of dots (0=5x7 or 1=5x10)).
  //X=don't care

  uint8_t num_lines_ptn = g_num_lines - 1 << 3;
  uint8_t dot_format_ptn = 0x00;      //5x7 dots.  0x04 is 5x10

  commandWriteNibble(num_lines_ptn | dot_format_ptn);
  delayMicroseconds(60);

  //The rest of the init is not specific to 4-bit mode.
  //NOTE: we're writing full bytes now, not nibbles.

  // display control:
  // turn display on, cursor off, no blinking
  // 
  commandWrite(CMD_DISPLAY | CMD_DISPLAY_DISPLAY_ON/*0x0C*/);
  delayMicroseconds(60);

  //clear display
  commandWrite(CMD_CLEAR);
  delay(3);

  // entry mode set: 06
  // increment automatically, display shift, entire shift off

  commandWrite(0x06);
  delay(1);//TODO: remove unnecessary delays
}
开发者ID:tort32,项目名称:BrooderAVR,代码行数:55,代码来源:LCD4Bit_mod.cpp


示例10: main

int main() {

    unsigned int x = 0x4a;   /* 01001010 (74) */
    unsigned int y = 0x3c;   /* 00111100 (60) */

    printf("x: %x\n", x);
    printf("y: %x\n", y);
    
    /* setbits(x, 4, 4, y):
     *
     * x = 0  1  0  0  1  0  1  0
     *     7  6  5  4  3  2  1  0
     *              ^--------^
     *
     * The 4 bits that begin at position 4 must be set to the
     * rightmost 4 bits of y.
     *
     * y = 0  0  1  1  1  1  0  0
     *                 ^--------^
     *
     * These 4 bits should replace the 4 in x.
     *
     * x = 0  1  0  1  1  0  0  0
     *              ^--------^
     *
     * In decimal this is 88.
     */

    printf("setbits(x, 4, 4, y) = %d\n", setbits(x, 4, 4, y));

}
开发者ID:imwally,项目名称:knr,代码行数:31,代码来源:ex2-6.c


示例11: compute_ham_similarity_64

//Note: it takes size and offset in units of byte
static inline int compute_ham_similarity_64(unsigned short* ref, unsigned short* circ_array, 
                                int size){
	
    const uint8_t*         	ref_c=(uint8_t*) ref;
    const uint8_t*         	circ_c=(uint8_t*) circ_array;
    register uint8x16_t     a,b;
    register uint8x16_t     c,d,temp;
    register uint16x8_t     acc;
    register uint           i=0,count=0;
	int 					j=0;
	int 					shift=size&0xF;
	for(i=0;i<=size-16; i+=16){
		j++;
		a=vld1q_u8(&ref_c[i]);
		b=vld1q_u8(&circ_c[i]);
		c=veorq_u8(a,b);
		acc=vaddq_u16(acc,vpaddlq_u8(vcntq_u8(c)));
	}	
	count=setbits(acc);
	a=vld1q_u8(&ref_c[i]);
	b=vld1q_u8(&circ_c[i]);
	c=veorq_u8(a,b);
	c=vcntq_u8(c);
	
	for(i=0;i<shift;i++){
		count=count+vgetq_lane_u8 (c,i);
	}
    return size*8-count;
}
开发者ID:umgupta,项目名称:hamming_code,代码行数:30,代码来源:compute_hamming_similarity.c


示例12: encode_type1002

/* encode type 1002: extended L1-only gps rtk observables --------------------*/
static int encode_type1002(rtcm_t *rtcm, int sync)
{
  int i, j;
  int code1, pr1, ppr1, lock1, amb, cnr1;

  /* encode header */
  i = encode_head(1002, rtcm, sync, rtcm->n);

  for (j = 0; j < rtcm->n; j++) {

    /* generate obs field data gps */
    gen_obs_gps(rtcm, &(rtcm->obs[j]), &code1, &pr1, &ppr1, &lock1, &amb,
                &cnr1);

    setbitu(rtcm->buff, i, 6, rtcm->obs[j].prn+1  ); i += 6;
    setbitu(rtcm->buff, i, 1, code1); i += 1;
    setbitu(rtcm->buff, i, 24, pr1  ); i += 24;
    setbits(rtcm->buff, i, 20, ppr1 ); i += 20;
    setbitu(rtcm->buff, i, 7, lock1); i += 7;
    setbitu(rtcm->buff, i, 8, amb  ); i += 8;
    setbitu(rtcm->buff, i, 8, cnr1 ); i += 8;
  }
  rtcm->nbit = i;
  return 1;
}
开发者ID:RoboBil,项目名称:piksi_firmware,代码行数:26,代码来源:rtcm.c


示例13: rtcm3_encode_1002

/** Encode an RTCMv3 message type 1002 (Extended L1-Only GPS RTK Observables)
 * Message type 1002 has length `64 + n_sat*74` bits. Returned message length
 * is rounded up to the nearest whole byte.
 *
 * \param buff A pointer to the RTCM data message buffer.
 * \param id Reference station ID (DF003).
 * \param t GPS time of epoch (DF004).
 * \param n_sat Number of GPS satellites included in the message (DF006).
 * \param nm Struct containing the observation.
 * \param sync Synchronous GNSS Flag (DF005).
 * \return The message length in bytes.
 */
u16 rtcm3_encode_1002(u8 *buff, u16 id, gps_time_t t, u8 n_sat,
                      navigation_measurement_t *nm, u8 sync)
{
  rtcm3_write_header(buff, 1002, id, t, sync, n_sat, 0, 0);

  u16 bit = 64; /* Start at end of header. */

  u32 pr;
  s32 ppr;
  u8 amb, lock, cnr;

  for (u8 i=0; i<n_sat; i++) {
    gen_obs_gps(&nm[i], &amb, &pr, &ppr, &lock, &cnr);

    setbitu(buff, bit, 6, nm[i].sid.sat); bit += 6;
    /* TODO: set GPS code indicator if we ever support P(Y) code measurements. */
    setbitu(buff, bit, 1,  0);    bit += 1;
    setbitu(buff, bit, 24, pr);   bit += 24;
    setbits(buff, bit, 20, ppr);  bit += 20;
    setbitu(buff, bit, 7,  lock); bit += 7;
    setbitu(buff, bit, 8,  amb);  bit += 8;
    setbitu(buff, bit, 8,  cnr);  bit += 8;
  }

  /* Round number of bits up to nearest whole byte. */
  return (bit + 7) / 8;
}
开发者ID:ejconlon,项目名称:libswiftnav,代码行数:39,代码来源:rtcm3.c


示例14: main

int main()
{
	printf("%d", setbits(255, 4, 3, 254));
	
	return 0;

}
开发者ID:Liquifier,项目名称:K-R,代码行数:7,代码来源:06.c


示例15: main

int main(int argc, char *argv[])
{
  int x,p,n,y;
	
  if (argc != 5){
    printf("usage: x p n y\n");
    return 1;
  }

  x = atoi(argv[1]);
  p = atoi(argv[2]);
  n = atoi(argv[3]);
  y = atoi(argv[4]);

  printf("setbits with arguments x=%d, p=%d, n=%d, y=%d\n",x,p,n,y);
  printf("x before:\n");
  printBinary(x);
  printf("y before:\n");
  printBinary(y);

  x = setbits(x,p,n,y);
  printf("After set bits:\n");
  printBinary(x);
  return 0;
}
开发者ID:Gnibur,项目名称:Learning-C,代码行数:25,代码来源:ex2-6.c


示例16: main

int main(void){
    int x = 2, y = 3;
    printbits("x", x);
    printbits("y", y);

    printbits("z", setbits(x, 3, 3, y));
}
开发者ID:eudisd,项目名称:k-r,代码行数:7,代码来源:2-6.c


示例17: main

int main(){

	unsigned int a, b;
	char* p, *q, *r, *s;

	a = 0xFF;
	b = 0x00;
	p = getbitstr(a);
	q = getbitstr(~0);
	r = getbitstr(b);

	printf("the ~0 is: %d\n", ~0);
	printf("the bit string of ~0 is %s.\n", q);
	printf("the bit string of a is %s.\n", p);
	// test
	printf("the bit string of b is %s.\n", r); 
	s = getbitstr(setbits(a, 6, 3, b));	
	printf("after setbits(a, 6, 3, b), bit string of a is: %s.\n", s);

	free((char*)p);
	free((char*)q);
	free((char*)r);
	free((char*)s);	
	p = NULL;
	q = NULL;
	r = NULL;
	s = NULL;
	return 0;
}
开发者ID:smileboywtu,项目名称:The-C-Programming-Language-2nd,代码行数:29,代码来源:bitwise.c


示例18: main

/* exercise2-6 - Write a function setbits(x,p,n,y) that returns x with
 * the n bits that begin at position p set to the rightmost n bits of y,
 * leaving the other bits unchanged. 
 * 
 * exercise2-6.c - prompts the user for values, applies 
 * setbits(x,p,n,y), and the prints the result.  Will not return an
 * error if given non-decimal-number input. 
 * 
 * NOTE: This implementation begs a more elegant solution. */
int main()
{
	char numstring[MAXLINE];
	
	unsigned x, y;
	int p, n;
	
	//prompt user for x (number to transform)
	printf("enter a number to apply setbits(x, p, n, y) to: ");
	gets(numstring);
	x = (unsigned) atoi(numstring);
	
	//prompt user for p (position)
	printf("enter a number p corresponding to the position: ");
	gets(numstring);
	p = atoi(numstring);
	
	//prompt user for n (number of digits)
	printf("enter a number n corresponding to the number of digits: ");
	gets(numstring);
	n = atoi(numstring);
	
	//prompt user for y (transformant)
	printf("enter a number y to apply the righmost n bits from: ");
	gets(numstring);
	y = (unsigned) atoi(numstring);
	
	//print result
	printf("\nThe resulting transformation of x is: %u\n", setbits(x, p, n, y));
	
	return 0;
}
开发者ID:hulatang,项目名称:K-R-The-C-Programming-Language-Exercise-Answers,代码行数:41,代码来源:exercise2-6.c


示例19: main

main(){
    int r= getbits(0xdddd,10,3);
    printf("%d\n",r);
    int r1= setbits(0xffff,10,8,0x4444);
    printf("%d  %d",r1,0xffff);

} 
开发者ID:zhenbeiju,项目名称:cpractise,代码行数:7,代码来源:setbits.c


示例20: main

int main(void)
{
	unsigned i;
	unsigned j;
	unsigned k;
	int p;
	int n;

	for(i = 0; i < 30000; i += 511)
	{
		for(j = 0; j < 1000; j += 37)
		{
			for(p = 0; p < 16; p++)
			{
				for(n = 1; n <= p + 1; n++)
				{
					k = setbits(i, p, n, j);
					printf("setbits(%u, %d, %d, %u) = %u\n", i, p, n, j, k);
				}
			}
		}
	}

	return 0;
}
开发者ID:xiaoxigua,项目名称:theclang,代码行数:25,代码来源:exercise-2-6.c



注:本文中的setbits函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ setbits32函数代码示例发布时间:2022-05-30
下一篇:
C++ setbbox函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap