![]() |
Forum Index : Microcontroller and PC projects : Left shifting bits in mmbasic on maximite
Author | Message | ||||
steveizett Newbie ![]() Joined: 15/05/2012 Location: AustraliaPosts: 21 |
Hi guys I'm playing with a hx711 and need to implement the following code. for (i=0;i<24;i++){ ADSK=1; Count=Count<<1; ADSK=0; if(ADDO) Count++; } ADSK=1; Count=Count^0x800000; ADSK=0; return(Count); How do I shift left as in "Count<<1" I see in the manual a reference to RShift = nbr\(2^bits) Thanks very much. Steve |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
Shifting one bit to the left is the same as multiplying by 2. However the code you posted should work with a little modification as MMbasic does support shifting and XOR'ing. From the manual page 49. (Make sure the Count variable is an INTEGER!) [code] Shift operators: x << y x >> y These operate in a special way. << means that the value returned will be the value of x shifted by y bits to the left while >> means the same only right shifted. They are integer functions and any bits shifted off are discarded and any bits introduced are set to zero. [/code] The ^ operator is called XOR in MMBasic. (You can find that on the same page). Microblocks. Build with logic. |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1573 |
@steveizett LShift = nbr *(2^bits)
I think (AFAIK) the MMBasic (4.5) for Maximites has no shift operators. ... also no integers. Regards Michael causality ≠ correlation ≠ coincidence |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
Oops, missed the Maximite reference in the topic. Just use: [code] Count = Count * 2 [/code] Microblocks. Build with logic. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6269 |
Remember that you are limited to about 23 bits for integers in 32 bit floating point. Jim VK7JH MMedit |
||||
steveizett Newbie ![]() Joined: 15/05/2012 Location: AustraliaPosts: 21 |
Thanks guys for the help Sounds like I need to use micromite for this app. Cheers Steve |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |