342. Power of Four

本文介绍了一种高效判断整数是否为4的幂的方法,利用位运算的特性,通过三个步骤实现:验证num大于0、确保二进制表示中只有一个1以及通过位运算替代取模操作检查(num-1)%3是否等于0。

题目大意:判断一个整数num是不是4的指数,不用循环和递归的情况下。

思路:(借鉴)

4指数的整数的二进制表示只有1个1.其他全为0,于是num&(num-1)=0

4^n可以分解为3*(4^0+4^1+4^2...+4^(n-1)),于是(num-1)%3=0,貌似这一步可以更优化,采用位运算代替取模。

code:

bool isPowerOfFour(int num) {
     return num > 0 && (num & (num - 1)) == 0 && (num - 1) % 3 == 0;
}

ADC Reset Command The ADC reset command RESET [0000 0110] resets the ADC to the default values. 3.4 ADC Programming Sequence – Power Up At power-up it is necessary to initialize all the ADC registers. The sequence is: 1. Set the CS_EE to high to disable EEPROM communication. 2. Set the CS_ADC to low to enable ADC communication. 3. Initialize all four configuration registers to the default values in the EEPROM’s Relative addresses 61, 63, 65 and 67 (see the MSB bytes in see Section 3.0) by sending a WREG command to address 0 [0100 0011] followed by the four bytes of data: • Send the the Reset command (06h) to make sure the ADC is properly reset after powerup • Write the respective register configuration using the WREG command (Example: 43h, 0Ah, 84h, 40h, and 00h) Both a temperature and an uncompensated pressure reading are necessary to calculate a compensated value (see Section 3.5). 3.5 ADC Programming and Read Sequence – Temperature Reading (see Figure 3-2 and Table 3-3) 1. Set the CS_ADC low to enable ADC communication. 2. Configure the sensor to temperature mode and the desired data rate by setting configuration register 1 by sending a WREG command to address 1, [0100 0100] followed by the single configuration byte. Bit 1 (TS) of the configuration register should be set to 1. 3. Send 08h command to start data conversion on ADC. 4. The sensor will start to output the requested data on DOUT at the first SCLK rising edge after the command byte is received
最新发布
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值