当前位置: 首页>>代码示例>>C++>>正文


C++ setbits函数代码示例

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


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


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