Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:38 28 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : [PicoVGA] Doubt with shift << >>

Author Message
ice2642

Regular Member

Joined: 27/05/2023
Location: Brazil
Posts: 82
Posted: 12:00pm 27 Jul 2023
Copy link to clipboard 
Print this post

Hello,

Sorry about my English, I hope you understand what I want to ask.

I would like to know if in the MMbasic << >> is like in C change the binary value for ex 0001 with 2 << wil go to 0100 ?
I do not understand how to use it in Basic.

Can we give me a little example?

Thank you in advanced.

Best Regards,
MMBasic 5.0707 on PicoMite VGA
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1114
Posted: 12:12pm 27 Jul 2023
Copy link to clipboard 
Print this post

<< is Bitshift left ..


as you might see, every Shift left doubles the Value:
the number behind << is the Counter of the "shifts"
0001 << 2 = 1*4 so the you'll get 0100

in Basic it is simply:

a=1
a=a<<2
?a
n=32
n=n>>2
?n


Edited 2023-07-27 22:16 by Martin H.
'no comment
 
ice2642

Regular Member

Joined: 27/05/2023
Location: Brazil
Posts: 82
Posted: 12:15pm 27 Jul 2023
Copy link to clipboard 
Print this post

  Martin H. said  << is Bitshift left ..


as you might see, every Shift left doubles the Value:
the number behind << is the Counter of the "shifts"
0001 << 2 = 1*4 so the you'll get 0100


I get,

Thank you.
MMBasic 5.0707 on PicoMite VGA
 
ice2642

Regular Member

Joined: 27/05/2023
Location: Brazil
Posts: 82
Posted: 12:50pm 27 Jul 2023
Copy link to clipboard 
Print this post

Have some advantage to use a<<2 instead A^2 in BASIC?

Speed or some like this?

Thank you.
MMBasic 5.0707 on PicoMite VGA
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2136
Posted: 01:06pm 27 Jul 2023
Copy link to clipboard 
Print this post

Needs fewer clock cycles.
> timer=0:for x=0 to 999999:n=2^8:next:?timer
13733.523
> timer=0:for x=0 to 999999:n=1<<8:next:?timer
12520.537
> timer=0:for x=0 to 999999:n=1:next:?timer
11138.736
>
 
ice2642

Regular Member

Joined: 27/05/2023
Location: Brazil
Posts: 82
Posted: 01:07pm 27 Jul 2023
Copy link to clipboard 
Print this post

  phil99 said  Needs fewer clock cycles.
> timer=0:for x=0 to 999999:n=2^8:next:?timer
13733.523
> timer=0:for x=0 to 999999:n=1<<8:next:?timer
12520.537
> timer=0:for x=0 to 999999:n=1:next:?timer
11138.736
>


Cool,

Thank you :)
MMBasic 5.0707 on PicoMite VGA
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024