Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What does this line mean ?
#11
Is there somewhere I could find out more about this. I've been procrastinating on some screen 12 animation. I need a good bit shift algorithm.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply
#12
A bit shift is just a fast way of multiplying or dividing by 2^n. There's no way to do true bit shifts with just QB; all you can do is multiply or divide.

i<<n becomes i * 2^n
i>>n becomes i \ 2^n
Reply
#13
Quote:I found this line of code while working on Perlin noise:

n = (n<<13) ^ n

It's C, I guess, and I can't guess how to translate that into Basic...

Can anybody help ?

jark...if it's c++ then "^" is the bitwise XOR, not "to the power of".
As such, I read:
// c++ code
n = (n<<13) ^ n;
// end of c++

as equivalent to:
' QB4.5 code
n = (n * (2 ^ 13)) XOR n
' end of QB code

cheers.

c++ makes goofy use of symbols where the same symbol has different meanings, depending on context.

Here's a basic rundown:

+, -. /, *.....as expected...usually

! NOT (bitwise or logical)
& AND (bitwise) unless it is in front of a variable, in which case it means "return the address of this variable"
&& AND (logical)
| OR (bitwise)
|| OR (logical)
^ XOR (bitwise)
% MOD
<, >, <=, <= (logical evaluators)
<<, >> (bitshift operators)
<< overloaded class inserter eg cout << "Hello world"; is equivalent to the Basic PRINT "Hello world"
>> overloaded extractor eg cin << x; is equivalent to the Basic INPUT x
= assignment
== logical equivalence evaluator

but then...you have to be on the lookout for other uses...for example, is one form of the "points to" operator, not "minus minus greater than" ;-)
Reply
#14
Crap, I forgot that ^ was XOR in C. Smile
Reply
#15
I think "Crap" is kind of a "Et Zut", which means "fuck" in my mother language...

I will have to test all that stuff until Hugo Elias's routine becomes clear for me and others.

But after all, that what I did when I tried to plot my first Buddhabrot: testing! And now, it works...
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#16
Is there a === in c++?
Reply
#17
Quote:Is there a === in c++?
That's just in flash.
am an asshole. Get used to it.
Reply
#18
IF "n<<13 " in C means shift left 13 bits, the Plasma's translation is correct, and Mango's won't work.
*****
Reply
#19
Quote:(n * 2^13)
Quote:(n * (2 ^ 13))

No Moneo, it's the same. The only difference is that Plasma had mistaken ^ for power instead of XOR.
Reply
#20
Quote:IF "n<<13 " in C means shift left 13 bits, the Plasma's translation is correct, and Mango's won't work.
*****

Code:
moneo...regarding your comment about the QB translation of n = (n<<13) ^ n  :


n = (n * 2^13) ^ n
     --------  -
        |      |
        |      |
        |      \-- problem here.  in C++
        |             the symbol "^" means "XOR"
        |
        |
        |
        |
        \-   OK...no problem...QB notation
                       It's the same (a*b^c) = (a*(b^c))
                       due to precidence.  I included
                       the extra parentheses for clarity.


The original post wanted to know what:

z = (z << p) ^ z

meant.  I simply stated (without pointing out earlier errors)  that if it is c-code,  it means:

z = (z multiplied by  (2 to the p power)) XOR z

or, in qb equivalent:
z = (z * (2 ^ p)) XOR z

which it does...if it is c code.

Cheers
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)