BBC BASIC for Windows
« how to »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:55pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: how to  (Read 422 times)
quadpughbellsouth
New Member
Image


member is offline

Avatar




PM


Posts: 0
xx how to
« Thread started on: Feb 2nd, 2014, 12:34pm »

How do you the right shift operator ">>"

a few examples would help

thanks
nick smiley
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: how to
« Reply #1 on: Feb 2nd, 2014, 1:14pm »

on Feb 2nd, 2014, 12:34pm, quadpughbellsouth wrote:
How do you the right shift operator ">>"
a few examples would help

The informal syntax is:

Code:
      result = number >> shift 

Where number is a numeric value (assumed integer) and shift is the number of bits by which you want to shift it.

So for example if you do:

Code:
      PRINT %10101010 >> 3 

the result will be %10101, or 21 in decimal.

For positive numbers the right-shift operator is equivalent to dividing by the equivalent power-of-two, so for example:

number >> 1 gives the same result as number DIV 2
number >> 2 gives the same result as number DIV 4
number >> 3 gives the same result as number DIV 8

But that equivalence doesn't necessarily apply for negative numbers.

Google will find you many web pages describing the shift operators and their uses, for example here (strictly it is talking about Java but the BBC BASIC shifts work just the same):

http://stackoverflow.com/questions/141525/absolute-beginners-guide-to-bit-shifting

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls