#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    3
    Rep Power
    0

    Problems with rotating a byte in vb6


    Hello guys,
    i am trying to rotate a byte in VB6 witout a CARRY(left and right ) .
    i am doing it OK ,it works.
    But, i dont know how to rotate a byte with a CARRY !
    Do you have any kind of code that can show me how to rotate a byte left and right with a CARRY in VB6?
    THANKS !
    here is my code :

    Public Function shrByte(ByVal Value As Byte, ByVal Shift As Byte) As Byte
    shrByte = Value
    If Shift > 0 Then
    shrByte = Int(shrByte / (2 ^ Shift))
    End If
    End Function

    Public Function shlByte(ByVal Value As Byte, ByVal Shift As Byte) As Byte
    shlByte = Value
    If Shift > 0 Then
    Dim i As Byte
    Dim m As Byte
    For i = 1 To Shift
    shlByte = (shlByte And &H7F) * 2
    Next i
    End If
    End Functio
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    45
    Try this:
    Code:
    Public Function shlByte(ByVal Value As Byte, ByVal Shift As Byte) As Byte
        Dim i As Byte
        Dim m As Byte
        shlByte = Value
        If Shift > 0 Then
            For i = 1 To Shift
                m = shlByte / 256
                shlByte = (shlByte And &H7F) * 2 + m
            Next i
        End If
    End Function
    
    Public Function shrByte(ByVal Value As Byte, ByVal Shift As Byte) As Byte
        Dim i As Byte
        Dim m As Byte
        shrByte = Value
        If Shift > 0 Then
            For i = 1 To Shift
                m = (shrByte Mod 2) * 128
                shrByte = shrByte / 2 + m
            Next i
        End If
    End Function
    J.A. Coutts
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    3
    Rep Power
    0

    problems with byte rotating in vb6


    Hi,
    thanks for the quick answer,
    i am having a problem while trying to write the right rotate byte (without carry ) functions "<<" and ">>" . i am trying to do the same like the functions << and >> are in the C language . here is my code :

    Public Function shrByteInt(ByVal Value As Byte, ByVal Shift As Byte) As Integer
    shrByteInt = Value
    If Shift > 0 Then
    shrByteInt = Int(shrByteInt / (2 ^ Shift))
    End If
    End Function

    HashBuf(0) = 0
    HashBuf(1) = 0
    'HashBuf(2) = 0
    j = 0
    For i = 0 To 2
    bVal = (shrByteInt(bBuffer(i), 7))
    bVal = bVal And &H1
    If (bVal = 1) Then
    HashBuf((j / 8)) = (HashBuf(j / 8)) Or (Int(2 ^ (j Mod 8)))
    End If
    'End If
    bVal = (shrByteInt(bBuffer(i), 6))
    bVal = bVal And &H1
    If (bVal = 1) Then
    HashBuf((j + 1) / 8) = (HashBuf((j + 1) / 8)) Or (Int(2 ^ ((j + 1) Mod 8)))
    End If
    j = j + 2
    Next

    At the C code (while using the "<<" and ">>" operators ) i am getting the output of (result of hashbuf ) : 1 63 0
    and in my code(VB6) i am getting the input : 1 31 32
    31+32 =63 and somehow the VB6 compiler is putting 63 into 2 bytes instead of one . i dont understand why
    do you have any idea ?
    thanks !
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    3
    Rep Power
    0

    Thumbs down


    Dim bVal As Integer
    Dim HashBuf(2) As Byte
    Dim bBuffer(8) As Byte
    For i = 0 To 8
    bBuffer(i) = 240
    Next

    the output is :
    in C language :
    bval=1
    hashbuf[0]=63
    hashbuf[1]=0

    in VB6 language:
    bval=1
    hashbuf[0]=31
    hashbuf[1]=32
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    45
    Sorry, but I could make sense of your code snippets because they are incomplete. With Notepad, open your form (eg. Form1.frm). Scroll down and highlight and copy only the code. Paste it into your reply and place the code tags in front of and behind.

    square left bracket & "code" & square right bracket
    your code here
    .....
    ...
    ..
    square left bracket & "/code" & square right bracket

    J.A. Coutts

IMN logo majestic logo threadwatch logo seochat tools logo