1. ?? shift left

Quoting the library reference :

 "There are no routines for shifting bits left or right,
 but you can achieve the same effect by multiplying or dividing
 by powers of 2."


 These are my examples :
         1: 5 shifted-left 2 is equal to 20
         2: 7 shifted-left 16 is equal to 458752
 
 Now how can you do this with the power() function ??

Bernie

new topic     » topic index » view message » categorize

2. Re: ?? shift left

5 * power(2, 2) = 20
7 * power(2, 16) = 458752

so to shift x left by p, use x * power(2, p)
and to shift x right by p, use x / power(2, p)

Jeff Fielding
----- Original Message ----- 
From: "Bernie Ryan" <xotron at localnet.com>
To: "EUforum" <EUforum at topica.com>
Subject: ?? shift left


> 
> 
> 
> Quoting the library reference :
> 
>  "There are no routines for shifting bits left or right,
>  but you can achieve the same effect by multiplying or dividing
>  by powers of 2."
> 
> 
>  These are my examples :
>          1: 5 shifted-left 2 is equal to 20
>          2: 7 shifted-left 16 is equal to 458752
>  
>  Now how can you do this with the power() function ??
> 
> Bernie
> 
> 
> 
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: ?? shift left

Something like ...

function shift_bits(integer x, integer steps)
    return x * power(2, -steps)
end function

where -ve steps move bits to the left, and +ve to the right.

------
Derek Parnell
Melbourne, Australia
"To finish a job quickly, go slower."

----- Original Message ----- 
From: "Chris Bensler" <bensler at mailops.com>
To: <EUforum at topica.com>
Sent: Monday, May 14, 2001 10:46 PM
Subject: RE: ?? shift left


> 
> How about just shift_bits(x,steps)
> step could positive or negative..
> 
> Chris
> 
> stabmaster_ at HOTMAIL.COM wrote:
> > How about shl_bits(x, steps) and shr_bits(x, steps) in v. 2.3 ?   Or 
> > perhaps 
> > it should be sal/sar since euphoria integers are signed..
> >

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu