Routines to Create and Decipher a Bit String Representation

Category:
Miscellaneous
Type:
Snippets
Difficulty:
Intermediate

Author: Robert R. Thele

Version Compatibility: Visual Basic 6, Visual Basic 5, Visual Basic.NET

More information:
These two routines will convert any Byte, Integer, Long, or String data type into a visual (string) representaion of its bit patterns and vice versa. I.e. ConvertToBitPattern(CInt(-123)) will return: 11111111 10000101, while: ConvertFromBitPattern("11111111 10000101",vbInteger) will return: -123

These functions could easily be made more efficient, but where written to demonstrate some of the principles behind bit patterns, particularly those of negative Integers and Longs. All general conversion errors are trapped and will result in a descriptive error message.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: