Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / What do the '>>' and the '

Author
Message
KOL
22
Years of Service
User Offline
Joined: 10th Aug 2003
Location:
Posted: 10th Aug 2003 21:15
I've been programming for a long time, and I've come across the use of the '' operators. I'm not quite sure how they are used, although they look like some sort of math operators. As in the example of:

for i = 1 to 20
print str$(i >> 1);" ";str$(i >> 2);" ";str$(i >> 3);" ";str$(i >> 4)
Next i

wait key

VS.

for i = 1 to 20
print str$(i
KOL
22
Years of Service
User Offline
Joined: 10th Aug 2003
Location:
Posted: 10th Aug 2003 21:24
I'll try that again.......

I've been programming for a long time, and I've come across the use of the >> and << operators. I'm not quite sure how they are used, although they look like some sort of math operators. (See Code)

Could anyone give an explination as to the proper use of these operators> (as the Reference & User Manuals say nothing about them, and I haven't been able to locate anything in the Serach)
Scharmers
23
Years of Service
User Offline
Joined: 4th Jul 2003
Location:
Posted: 10th Aug 2003 22:19
They are bit-shift operators. You see them a lot in C. Go to Google and do a search on bit-shift and c, and you'll probably get a better explanation on what they do than how I can explain them.

KOL
22
Years of Service
User Offline
Joined: 10th Aug 2003
Location:
Posted: 10th Aug 2003 22:47
Thanks Scharmers,

To quote from Deitel & Deitel....

The left shift operator (<< shifts the bits of its left operand to the left by the number of bits specified in its right operand. Bits vacated to the right are replaced with 0s; 1s shifted off the left are lost. ie 960 (00000011 11000000) 960 << 8 = 49152 (11000000 00000000).

The right shift operator (>> shifts the bits of its left operand to the right by the number of bits specified in its right operand. ie 960 (00000011 11000000) 960 >> 8 = 3 (00000000 00000011).


At times I not sure when DB/DBPro switches to C syntax and when it's just BASIC syntax.....

Login to post a reply

Server time is: 2026-07-07 07:34:34
Your offset time is: 2026-07-07 07:34:34