342. Power of Four

本文介绍了一种高效的方法来判断一个给定的32位整数是否为4的幂。该方法避免了使用循环或递归,并通过特定的位操作实现了这一目的。

Given an integer (signed 32 bits), write a function to check whether it is a power of 4.

Example:
Given num = 16, return true. Given num = 5, return false.

Follow up: Could you solve it without loops/recursion?

思路:

首先必须是2的平方,其次减去1之后可以被3整除。

public class Solution {
    public boolean 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、付费专栏及课程。

余额充值