circular left shift in VB

  • Thread starter Thread starter sandhya
  • Start date Start date
S

sandhya

Hello Folks,

i hava a problem in coding of circular left shift of 25 bits in my
program...how do i perform it, and how do i use unsigned in VB.
My program (IDEA algorithm implementation in VB) requires unsigned
bits...so how do i go thro this ,since VB does not support unsigned
operations


Post your suggestions!!!

Many thanks,
Sandhya
 
sandhya said:
bits...so how do i go thro this ,since VB does not support unsigned
operations

If you have VB2005, it does support unsigned values using the UShort,
UInteger, ULong types.

But you can still use signed types as the bits will still be shifted.

Can you provide a little more detail on what you are attempting to do?
 
sandhya said:
i hava a problem in coding of circular left shift of 25 bits in my
program...how do i perform it, and how do i use unsigned in VB.
My program (IDEA algorithm implementation in VB) requires unsigned
bits...so how do i go thro this ,since VB does not support unsigned
operations
<snip>

You may try the following, although I must warn you that I didn't have
the time to stress test it:

Function LRoll25(ByVal Value As Integer, _
ByVal Count As Integer) As Integer
If Count >= 0 Then
Return ((Value << Count) And &H1FFFFFF) _
Or ((Value And &H1FFFFFF) >> (25 - (Count Mod 26)))
Else
Return ((Value And &H1FFFFFF) >> -Count) _
Or ((Value << (25 + (Count Mod 26)) And &H1FFFFFF))
End If
End Function

Count is the number of bits to roll left. Bits that fall beyond the
25th position (from right to left) will be rolled back into the value
from the right side. Negative values for Count will roll right
(yikes!).

Have fun, and best regards.

Branco.
 
i hava a problem in coding of circular left shift of 25 bits in my
program...how do i perform it, and how do i use unsigned in VB.
My program (IDEA algorithm implementation in VB) requires unsigned
bits...so how do i go thro this ,since VB does not support unsigned
operations

If you represent 25 bits as the low order 25 bits in a 32 bit integer, then
you can use the routine below. m is an integer whose low order 25 bits are
to be shifted. s is the number of bits to right shift, or if s is negative,
left shift.

Public Function ShiftRightCircular25(ByVal m As Integer, ByVal s As
Integer) As Integer
' Circular right shift the low order 25 bits of m by s bits.
' If s is negative, then circular left shift by -s bits.
' Return the shifted value with the high order 7 bits zeroed.
' The technique is to make two adjacent copies of m (50 bits total) in a
long,
' and then right shift an appropriate amount to handle a left or right
shift.
Const Mask As Long = &H1FFFFFF ' 25 low order 1 bits
Const Dup25 As Long = Mask + 2 ' a multiplier that duplicates 25 low
order bits
Dim x As Long = (m And Mask) * Dup25 ' two copies of m are now adjacent
in x
s = s Mod 25 ' a shift amount within the bounds -24 <= s <= +24
If s < 0 Then s += 25 ' convert a left shift to a right shift
x >>= s ' the low order 25 bits of x contain the output
Return CInt(x And Mask)
End Function
 
Back
Top