Another way to left shift a 32 bit data?


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132

    Default Another way to left shift a 32 bit data?

    Looking to left shift as fast as possible a 32 bit variable by n times.

    Obviously the first thought is by a PBP for-next loop n times. Slow.

    The second thought in Assembly loop. Much faster.

    Any other idea? Something like XOR etc?

    The 32 bit variable start always as 1 and this maybe can help finding a fast alternative to left shift the number.

    Thanks,
    Ioannis

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Another way to left shift a 32 bit data?

    Not sure if I've understood your problem but how about a fixed array of 32bit numbers, each a constant with 1 bit shifted left. Use n to index into the array.

    So the array would be initialised as 1,2,4,8,16,32,64 etc etc

    Code would look like Answer=Array[n]

    I guess you could do it as a table in code memory if you can find a way to index it.

    George
    Last edited by towlerg; - 21st November 2015 at 22:33.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Another way to left shift a 32 bit data?

    How about the DCD operator? Is that what you're looking for? Is it fast enough?
    DCD returns the decoded value of a bit number. It changes a bit number (0 - 31) into a binary number with only that bit set to 1. All other bits are set to 0.
    Code:
    B0 = DCD 2  ' Sets B0 to %00000100
    /Henrik.

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Another way to left shift a 32 bit data?

    Thanks for the ideas!

    About the time they take, I have to test it. But the George's idea I guess it needs a fixed time. The DCD may need different time for setting the first or last bit using a loop.

    Thanks for the replies.

    Ioannis

  5. #5
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Another way to left shift a 32 bit data?

    Where did you get a 32 bit variable that PBP knows about? Is this a feature of PBP3?
    Can you alias and access the same variable as the four bytes?
    Since towerg mentioned “array” I’m not sure. a single variable of a datatype isn’t an array.

  6. #6
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Another way to left shift a 32 bit data?

    You didn’t say what you want to do with the bit that drops off the end.
    Assuming you want what PBP shift would do with a byte, and just drop the end bit,
    and feed in a zero to the right.
    Code:
    dis var byte [4]
    
    BitwiseRotateLeft:						' bitwise rotate array
      @ rlf 	_dis+3		,F				; ditching the first bit
      @ rlf		_dis+2		,F				;
      @ rlf		_dis+1		,F				;
      @ rlf		_dis+0		,F				;
      @ bcf		_dis+3		,0				;clear MSB
    return
    So long as you can access the first byte by aliasing it, I’m sure the assembler is a continuous 4 bytes.

Similar Threads

  1. how to "shift" a data into led matrix display ?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 9th January 2015, 16:09
  2. Bit Shift difference between PIC16 and PIC18 ???
    By bambi123 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th February 2012, 01:04
  3. Shift Right, Left
    By tazntex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th July 2010, 15:28
  4. Replies: 2
    Last Post: - 7th March 2008, 02:16
  5. LCDOUT 4-bit data on 8-bit setting
    By breesy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 26th June 2006, 18:39

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts