GLBasic forum

Main forum => GLBasic - en => Topic started by: josemym2 on 2010-May-02

Title: Operator bitwise right shift
Post by: josemym2 on 2010-May-02
Hello,
Is there a way to implement the bitwise (>>)? I need it because it is running code in c + + and Java, and I wanted to do GLbasic

This is my code:
Code (glbasic) Select

FUNCTION transform: coord[], offset[],trans_coord[]

//'            Transform 3d coordinates into 2d positions based on the size of the screen AND an a y offset
//'
//'        coord: 3 dimensional coordinate TO be transformed TO an isometric 2d coordinate: list of 3 integers [x,y,z]
//'        offset: 2 dimensional offset FOR the isometric coordinate: list of 2 integers [x,y]
//'        Returns trans_coord: a 2d isometric coordinate: list of 2 integers [x,y]
//'
//'        Note: A side effect FOR speed: isometric transform scales x AND y values TO 1.118 times their
//'        actual value AND the z scale coordinate stays AS 1: therefore all sprites need TO be drawn with this ratio.
//    'transformation coordinates that are returned
   DIMDATA trans_coord[],0,0
//    'calculate x coordinate
   trans_coord[0]=(coord[0]-coord[1])+offset[0]
//    'calculates y coordinate
   trans_coord[1]=((coord[0]+coord[1])>>1)-coord[2]+offset[1]
   //RETURN trans_coord[]
ENDFUNCTION


thanks
Title: Re: Operator bitwise right shift
Post by: Quentin on 2010-May-02
functions ASL() and ASR()
Title: Re: Operator bitwise right shift
Post by: josemym2 on 2010-May-02
Thanks
Title: Re: Operator bitwise right shift
Post by: josemym2 on 2010-May-02
but where is the best for compatibility with the c++ operator ">>"?

Title: Re: Operator bitwise right shift
Post by: Quentin on 2010-May-02
you also can use the << operator directly using INLINE

Code (glbasic) Select

LOCAL a% = 2

INLINE
a = a << 3;
ENDINLINE

PRINT "a is now: " + a, 0, 0
SHOWSCREEN
KEYWAIT
Title: Re: Operator bitwise right shift
Post by: Scott_AW on 2010-May-03
Inline is a wonderful thing.
Title: Re: Operator bitwise right shift
Post by: josemym2 on 2010-May-03
Thanks a lot.