Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Varbinary() Manipulations
Message
From
03/04/2001 18:27:33
 
 
To
28/03/2001 09:39:54
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00489403
Message ID:
00491610
Views:
8
Hi Bill,

What about SUBSTRING and STUFF functions and some kind of conversion?
... other declarations
...
DECLARE @counter INT
DECLARE @curChar BINARY(1)
DECLARE @curKey  BINARY(1)
SET @counter = 1
WHILE @counter <= LEN( @bytData)
BEGIN
    SET @curChar = SUBSTRING( @bytData, @counter, 1)
    SET @curKey = SUBSTRING( @bytKey, @counter, 1)
    IF @counter % 2 = 0
        SET @curChar = @curChar | (@curKey + @KEY_OFFSET)
    ELSE
        SET @curChar = @curChar | (@curKey - @KEY_OFFSET)
    SET @bytData = CONVERT( VARBINARY, STUFF( @bytData, @counter, 1, @curChar))
    SET @counter = @counter + 1
END
...
Maybe I missed something, but in common this should work.

>A bit off-topic here but thought I'd get some info from some of the T-SQL/binary experts.
>
>I have a situation where I am trying to translate some VB code using some byte arrays into T-SQL code so I can run the functionality in a SQL stored procedure. I believe I have successfully converted most of the code but I'm stuck at the the point where there is some manipulation of the VB byte arrays and I don't quite see how I can do this in T-SQL ( or even if it's possible ). The relevant VB code is:
>Dim KEY_OFFSET As Long
>Dim bytKey() As Byte
>Dim bytData() As Byte
>Dim lNum As Long
>
>'...Set values for the various variables, then:
>
>For lNum = LBound(bytData) To UBound(bytData)
>    If lNum Mod 2 Then
>        bytData(lNum) = bytData(lNum) Xor (bytKey(lNum) + KEY_OFFSET)
>    Else
>        bytData(lNum) = bytData(lNum) Xor (bytKey(lNum) - KEY_OFFSET)
>    End If
>Next lNum
>I can ( or at least I think I can ) get most of the entities translated, i.e. the arrays bounds, Mod, and Xor I can translate. I am using T-SQL varbinary() for the equivalent VB byte arrays and the specific problem I am wrestling with is how to "replace" bits ( bytes? ) in the varbinary() variable like is done with the
>        bytData(lNum) = bytData(lNum) Xor (bytKey(lNum) + KEY_OFFSET)
>VB statement.
>
>Is this possible in T-SQL and if so, how?
>
>Thanks,
>Bill
Alex
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform