Savan,

Please run the code below, you will see the result of 101110>>3

Jared Clinton.

<cfscript>
numberInBinary = "101110";
PositionsToShiftRight = 3;
</cfscript>
<cfoutput>
<pre>
> 101110>>3
>
> and isn't the result
>
> 000100
>
#numberInBinary#>>#PositionsToShiftRight#=#FormatbaseN(BitSHRN(InputBaseN(nu
mberInBinary,2),PositionsToShiftRight),2)#

Exactly correct, the result isn't 000100 , it is 000101 as you might expect
from shifting 1011110 three places to the right

#numberInBinary#>>0=#FormatbaseN(BitSHRN(InputBaseN(numberInBinary,2),0),2)#
<br>

#numberInBinary#>>1=#FormatbaseN(BitSHRN(InputBaseN(numberInBinary,2),1),2)#
<br>

#numberInBinary#>>2=#FormatbaseN(BitSHRN(InputBaseN(numberInBinary,2),2),2)#
<br>

#numberInBinary#>>3=#FormatbaseN(BitSHRN(InputBaseN(numberInBinary,2),3),2)#
<br>

#numberInBinary#>>4=#FormatbaseN(BitSHRN(InputBaseN(numberInBinary,2),4),2)#
<br>

#numberInBinary#>>5=#FormatbaseN(BitSHRN(InputBaseN(numberInBinary,2),5),2)#
<br>

#numberInBinary#>>6=#FormatbaseN(BitSHRN(InputBaseN(numberInBinary,2),6),2)#
<br>

#numberInBinary#>>7=#FormatbaseN(BitSHRN(InputBaseN(numberInBinary,2),7),2)#
<br>

#numberInBinary#>>8=#FormatbaseN(BitSHRN(InputBaseN(numberInBinary,2),8),2)#
<br>

(by the way, you can only shift right 36 positions in cf)
</pre>
</cfoutput>



-----Original Message-----
From: laszlo [mailto:[EMAIL PROTECTED]]
Sent: Friday, 15 March 2002 9:17 AM
To: CF-Talk
Subject: Re: OT Thank god for markup


>>and isn't the result
>>000100
No, its' 101

>>changing the most significant byte to preserve the sign?
It's the most significatnt 'bit' not 'byte' (which was 0).

>>If you're using signed integers,...
Java's integral data types  (byte, short, int, long) are ALWAYS signed.

>>But Bit shifting is a very fast way of multiplying and integer dividing by
2.
Not 'really' true. Most compilers are smart enough to change
mutiplications/divisions by the power of 2 to bitwise shifts.

laszlo

"Matthew R. Small" wrote:

> It depends...
> If you're using signed integers, which in many cases are not important,
> then losing the most sig. bit would have the effect of changing the sign
> of the integer.  But Bit shifting is a very fast way of multiplying and
> integer dividing by 2.
>
> - Matt Small
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, March 14, 2002 5:04 PM
> To: CF-Talk
> Subject: OT Thank god for markup
>
> Situation: Studying for Sun Java Cert
>
> Question:
> What the !@#$@#$  is the point of a bitwise operator?
>
> can someone give me a reason that i would EVER want to use
>
> 101110>>3
>
> and isn't the result
>
> 000100
>
> changing the most significant byte to preserve the sign?
>
> OI!
>
> 

______________________________________________________________________
Why Share?
  Dedicated Win 2000 Server � PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
  Instant Activation � $99/Month � Free Setup
  http://www.pennyhost.com/redirect.cfm?adcode=coldfusionc
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to