Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

RE: There can be only one!

by Anonymous Monk
on May 15, 2000 at 21:19 UTC ( [id://11681]=note: print w/replies, xml ) Need Help??


in reply to There can be only one!

btw. what do the >> and << mean? they were in two cents also

Replies are listed 'Best First'.
RE: RE: There can be only one!
by vroom (His Eminence) on May 15, 2000 at 21:27 UTC
    They are bit-shift operators: They return the value of the left argument shifted left or right by the number of bits in the right argument.
    2<<4 #returns 32; 32>>3 #returns 4;


    vroom | Tim Vroom | vroom@cs.hope.edu
      could you explain this a little more in depth? i don't quite get what you mean by shifting the bytes
        Numbers represented in binary format ie: 000000101 #5 in decimal 1*2^2+1*2^0 #this shifted 1 place to the left is equivalent to #mutliplying by two 000001010 #this is equal to 10 or 1*2^3+1*2^1
        It shifts bits, not bytes. << moves the bits left and >> moves the bits right.
        2<<4 #2 is 00000010 in binary, the <<4 moves the bits left 4,00100000 + which is 32 32>>3 #32 is 00100000 in binary, the >>3 moves the bits right 3, 00000 +100 which is 4
        I hope this clears things up.
        >> and << shift bits, not bytes. Numbers are internally represented in digital computers using two-state bits. The bitshift operators shift these bits.

        For example 7 is 111 in binary. Shifting it one place left results in 1110 (digits coming from off the edge are zero), or 14. 111b shifted right once is 11 (a bit is shifted off), or 3. 7*2=14, and 7/2 is 3.5, the .5 is lost because of the one being shifted off.

        Hope this helps.

        okay, 1 = 00000001 2 = 00000010 3 = 00000011 4 = 00000100 and so on...... if you did 2<<3, you would shift 2 3 bits...... so you would have 10000, or 16.
        A byte is 8 bits. A bit is a 1 or a 0 that spells out the binary number corresponding to what you're trying to express. 2 in binary is 00000010. Shifting that to the left by 3 is this: 2 << 3 which yeilds 00010000 which is 8. shifting bits is like taking an eight bit number and rotating it in a certain direction.
        2 << 4 is 2 "left shifted" by four digits. In binary, 10.00000 is moved four digits to the left to result in 100000.0, or 32. Every time you move the decimal point in binary, you multiply or divide by two. So it's like moving the decimal point to multiply or divide by ten in decimal.
        this require some knowlege of binary numbers
        00000010 = 2
        if you shift that to the left four times
        00100000 =32

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11681]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-03-29 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found