New topic: 

Bit shifting

<http://forums.realsoftware.com/viewtopic.php?t=46167>

         Page 1 of 1
   [ 5 posts ]                 Previous topic | Next topic          Author  
Message        MadDoc          Post subject: Bit shiftingPosted: Fri Dec 07, 
2012 7:51 am                                 
Joined: Wed Oct 05, 2005 1:21 pm
Posts: 498
Location: United Kingdom                I recently dusted off an old project 
from years ago and am rewriting it from scratch.  It's a 6502 8-bit CPU 
emulator.

I'm trying to emulate an instruction that requires me to shift the contents of 
a UInt8 left by one bit position. 0 comes in on the right and bit 7 falls into 
the carry bit.

What's the most efficient way in RB to achieve this? The desired outcome would 
be:

start:  01100011
initial carry: 1

DO THE SHIFT

result: 11000110
end carry: 0

Thanks,      
_________________
Gorgeous REALbasic controls from Figa Software | My Flickr  | My Blog
11" MacBook Air 1.8Ghz i7, 4GB RAM, OSX 10.8.2, RB 2012 r1.1 Pro | iPhone 4S 
32GB | Nikon D60  
                             Top                jakuno          Post subject: 
Re: Bit shiftingPosted: Fri Dec 07, 2012 7:57 am                         
Joined: Fri Aug 31, 2012 3:56 pm
Posts: 25                Use: Bitwise.ShiftLeft or value=value*2   
                             Top                MadDoc          Post subject: 
Re: Bit shiftingPosted: Fri Dec 07, 2012 8:07 am                                
 
Joined: Wed Oct 05, 2005 1:21 pm
Posts: 498
Location: United Kingdom                Does the ShiftLeft() method bring a 0 
into bit 0?

How about something like this?

if BitAnd(data, &h80) = 0 then ' figure out the value of bit 7 of data
  carry = 0
else
  carry = 1
end if

data = Bitwise.ShiftLeft(data, 1)


I think this would work but I'm not sure if it's the most efficient way...      
_________________
Gorgeous REALbasic controls from Figa Software | My Flickr  | My Blog
11" MacBook Air 1.8Ghz i7, 4GB RAM, OSX 10.8.2, RB 2012 r1.1 Pro | iPhone 4S 
32GB | Nikon D60  
                             Top                jakuno          Post subject: 
Re: Bit shiftingPosted: Fri Dec 07, 2012 9:05 am                         
Joined: Fri Aug 31, 2012 3:56 pm
Posts: 25                You mean ROL (circular shift left)?

Try:

  const bitcount = 8
  dim value as integer
  
  value = (value * 2) + (Bitwise.ShiftRight(value, bitcount - 1) mod 2)
  value = value mod (2 ^ bitcount)   
                             Top                ktekinay          Post subject: 
Re: Bit shiftingPosted: Fri Dec 07, 2012 9:35 am                                
 
Joined: Mon Feb 05, 2007 5:21 pm
Posts: 290
Location: New York, NY                MadDoc wrote:Does the ShiftLeft() method 
bring a 0 into bit 0?
Yes, although that's easy enough to test, right?

Also, "x and y" is faster than "Bitwise.BitAnd( x, y )".      
_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.
  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 5 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to