May 31, 2018, 05:06 PM
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ů
Your comments are welcome. All of us are smarter than any one of us.
The Following 4 Users Say Thank You to rgsparber For This Useful Post:
Jon (Jun 1, 2018),
Seedtick (Jun 1, 2018),
volodar (Jun 17, 2018),
Workshopshed (Jun 2, 2018)
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.
Andy from Workshopshed
"Making and repairing things in a shed at the bottom of the garden"
The Following User Says Thank You to Workshopshed For This Useful Post:
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:
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.
Last edited by rgsparber; Jun 2, 2018 at 10:39 AM.
The Following User Says Thank You to rgsparber For This Useful Post:
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts