Question : How to convert Delphi SHL/SHR code to MS SQL

Hi gurus.

Unfortunately I am lost on how below delphi code can be converted into MS SQL udf. The DWORD value used in Delphi is saved as NUMERIC(10,0) in MS SQL.

Anyone (please!) help me on converted delphi code example to T-SQL? I need to take the NUMERIC(10,0) and break out Hour, Minute, Second and frames as SmallInt in a custom UDF.

Thanks in advance.
Code Snippet:
1:
2:
3:
4:
fr  := (dwTimeCode and $f) + (((dwTimeCode and $f0) shr 4) * 10);
     ss  := ((dwTimeCode and $f00) shr 8) + (((dwTimeCode and $F000) shr 12) * 10);
     mm  := ((dwTimeCode and $f0000) shr 16) + (((dwTimeCode and $F00000) shr 20) * 10);
     hh  := ((dwTimeCode and $f000000) shr 24) + (((dwTimeCode and $F0000000) shr 28) * 10);

Answer : How to convert Delphi SHL/SHR code to MS SQL

Operators in T-SQL :
AND => &
DIV => /

1 SHL 24 = 2^24 = 16777216
so :

((dwTimeCode and $f000000) shr 24) = (dwTimeCode shr 24) and $f
=> ( dwTimeCode / 16777216 ) & 15

even more :
hh = ( ( dwTimeCode / 16777216 ) & 15 ) + 10 * ( dwTimeCode / 268435456 ) & 15 )
mm  = ( (dwTimeCode / 65536 ) & 15 ) + 10 * ( (dwTimeCode / 1048576 ) & 15 )
ss  = ( (dwTimeCode / 256 ) & 15 ) + 10 * ( (dwTimeCode / 4096 ) & 15 )
fr  := (dwTimeCode & 15) + 10 * ( (dwTimeCode / 16 ) & 15)
Random Solutions  
 
programming4us programming4us