Good Day,
I have a number of binary strings that were created by a C app with a struct. Imagine, if you will, the struct looks like this:
struct {
int foo;
double bar; //Assume 8 bytes
char[20] baz;
}
Each string is 4 + 8 + 20 = 32 bytes long. The structure of the string looks something like this:
IIIIDDDDDDDDSSSSSSSSSSSSSSSSSSSS
I need to unpack this string in a TSQL stored proc. The string is easy:
baz = SUBSTRING(binarystring, 12, 20)
The int also. And then convert to an integer with bit shifting (well, multiplying by 2^4, 2^8, etc)
foo_string = SUBSTRING(binarystring, 0, 4)
foo = unpack_int(foo_string)
But, the double is a lot more challenging. I am able to do it by following the IEEE754 spec, I am not happy with doing this myself.
Is there a function or something that can unpack the int and double out of a binary string?
Thank you,
P.S. I've never used TSQL myself, so the above fragments may be illegal, but you get the notion. I'm assisting a colleague.