0
我正在創建檢查溫度並將數據發送到Xively protal的arduino項目。我找到了一些例子,但我不明白傳感器讀數方法中的位數。任何人都可以向我解釋嗎?尤其是紅利/ 10的部分?計算傳感器讀數中的位數(Arduino)
的方法是:
//This method calulates the number of digits in the sensor readind
//Since each digit of the ASCII decimal representation is a byte, the number
//of digits equals the numbers of bytes:
int getLength(int someValue)
{
//there's at least one byte:
int digits = 1;
//continually divide the value by ten, adding one to the digit count for
//each time you divide, until you are at 0
int getLength(int someValue) {
int digits = 1;
int dividend = someValue /10 ;
while (dividend > 0) {
dividend = dividend /10;
digits++;
}
return digits;
}
我真的很感激任何解釋