-
Arduino Byte Juggling
A very small population will have any interest in this topic. But if you are struggling with reads and writes of all data types to EEPROM, read on…
http://rick.sparber.org/ABJ.pdf
Your comments are welcome. All of us are smarter than any one of us.
Thanks,
Rick
-
Hi Rick, I had to do this kind of thing just the other day to send an integer over I2C.
To multiply by 2 you can shift the number one to the left so to multiply by 256 which is 2^8 you can do.
int b = a << 8;
A technique I used back when I was coding for my ZxSpectrum in the 1980s as it did not actually have a multiply operator.
-
Thanks Rick! We've added your Arduino Bit Shifting Method to our Miscellaneous category, as well as to your builder page: Rick's Homemade Tools. Your receipt:
<div id="blocks">
<div class="block b1 pngfix">
<div class="bimg">
<div>
<a href="http://www.homemadetools.net/homemade-arduino-bit-shifting-method"><img src="http://www.homemadetools.net/uploads/214272/homemade-arduino-bit-shifting-method.jpeg"/></a></div>
</div>
<div class="head pngfix"></div>
<div class="left pngfix"></div>
<div class="right pngfix"></div>
<div class="blockover b1 pngfix">
<div class="title">
<a href="http://www.homemadetools.net/homemade-arduino-bit-shifting-method">Arduino Bit Shifting Method</a>
<span> by <a href="/builder/Rick+Sparber">Rick Sparber</a></span>
</div>
<div class="tags">tags: <a href="http://www.homemadetools.net/tag/arduino">Arduino</a></div>
</div>
</div>
</div>
-
Yes, <<8 should do a multiply by 256. Be carful on shifting right:
long x = 0xFFEEDDCC;
x= (x>>8) & 0xFF;
Should produce 0x000000DD. Without the mask it would be 0xFFFFEEDD. It all depends on what you want.