From 519393f42e9ac9153df34e6a0260461e387cf196 Mon Sep 17 00:00:00 2001 From: Bodo Eggert <7eggert@gmx.de> Date: Thu, 8 Sep 2016 17:11:29 +0200 Subject: [PATCH] Save 66 bytes by using integer arithmetric --- DHT.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/DHT.cpp b/DHT.cpp index 86ad91c..583a0a9 100644 --- a/DHT.cpp +++ b/DHT.cpp @@ -45,9 +45,7 @@ float DHT::readTemperature(bool S, bool force) { break; case DHT22: case DHT21: - f = data[2] & 0x7F; - f *= 256; - f += data[3]; + f = ((word)(data[2] & 0x7F)) << 8 | data[3]; f *= 0.1; if (data[2] & 0x80) { f *= -1; @@ -78,9 +76,7 @@ float DHT::readHumidity(bool force) { break; case DHT22: case DHT21: - f = data[0]; - f *= 256; - f += data[1]; + f = ((word)data[0]) << 8 | data[1]; f *= 0.1; break; }