 Perl: the Markov chain saw PerlMonks

### RE: RE: RE: There can be only one!

 on May 16, 2000 at 04:35 UTC ( #11788=note: print w/replies, xml ) Need Help??

in reply to RE: RE: There can be only one!
in thread There can be only one!

could you explain this a little more in depth? i don't quite get what you mean by shifting the bytes

Replies are listed 'Best First'.
RE: RE: RE: RE: There can be only one!
by vroom (Pope) on May 16, 2000 at 04:53 UTC
```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
There can be only one!
by c-era (Curate) on May 16, 2000 at 19:07 UTC
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.
RE: RE: RE: RE: There can be only one!
by . (Acolyte) on May 18, 2000 at 04:06 UTC
>> 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.

RE: RE: RE: RE: There can be only one!
by base_16 (Beadle) on May 23, 2000 at 06:17 UTC
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.
RE: RE: RE: RE: There can be only one!
by Anonymous Monk on May 31, 2000 at 22:39 UTC
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.
Re: RE: RE: RE: There can be only one!
by Zorn (Initiate) on Oct 27, 2002 at 05:40 UTC
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.
Re: RE: RE: RE: There can be only one!
by thunders (Priest) on Sep 26, 2001 at 00:05 UTC
this require some knowlege of binary numbers
00000010 = 2
if you shift that to the left four times
00100000 =32

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11788]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2021-10-23 14:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My first memorable Perl project was:

Results (88 votes). Check out past polls.

Notices?