VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Reverse a character's bit pattern.

by TWLambe (3 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 25th May 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Reverse a character's bit pattern.

Rate Reverse a character's bit pattern.




'----------------------------------------------------
'   Function:   ReverseBits
'   Author:     TWLambe
'   Date:       25-May-2004
'   Description:
'   ------------
'   Returns a character whose bit pattern is the
'   reverse of the bit pattern of a supplied
'   character.
'
'   (Will only process the 1st. character if > 1
'    character is supplied).
'----------------------------------------------------
Dim w, x, y As Integer

    x = Asc(sChar)      'ASCII value of supplied char.
                        '(or 1st. character if more than 1)
    
    y = 0               'clear accumulated bit result
    
                        'mask each bit of ASCII value and
                        'if set, accumulate result with
    For w = 0 To 7      'reversed bit pattern
        If (x And (2 ^ w)) Then y = y + (2 ^ (7 - w))
    Next w              'repeat for each bit
    
    ReverseBits = Chr(y)
                        'set function return character,
                        'whatever it is !
End Function



Download this snippet    Add to My Saved Code

Reverse a character's bit pattern. Comments

No comments have been posted about Reverse a character's bit pattern.. Why not be the first to post a comment about Reverse a character's bit pattern..

Post your comment

Subject:
Message:
0/1000 characters