Hello
I have to convert T-SQL Code to SQLScript, and i have some troube in Binary manipulation like
Bitwise rotate left
Here is my Code :
-- Rotate bits left
CREATEFUNCTION bitrol
(
@x INT,
@s INT
)
RETURNSINT
BEGIN
RETURNCONVERT(INT,SUBSTRING(CONVERT(BINARY(8), CONVERT(BIGINT, CONVERT(BINARY(4), @x)) * POWER(2, @s)), 5, 4)) | CONVERT(INT,SUBSTRING(CONVERT(BINARY(8), CONVERT(BIGINT, CONVERT(BINARY(4), @x)) / POWER(2, 32 - @s)), 5, 4))
END
GO
-- Add two unsigned integers
CREATEFUNCTION add
(
@a INT,
@b INT
)
RETURNSINT
BEGIN
RETURNCONVERT(INT, SUBSTRING(CONVERT(VARBINARY, CONVERT(BIGINT, @a) + CONVERT(BIGINT, @b)), 5, 4))
END
GO
-- ff transformation
CREATEFUNCTION ff
(
@a INT,
@b INT,
@c INT,
@d INT,
@x INT,
@s INT,
@t INT
)
RETURNSINT
BEGIN
RETURN add(bitrol(add(add(@a, (@b & @c) | ((~@b) & @d)), add(@x, @t)), @s),@b)
END
GO
Thanks in advance