• I've had a quick look at this and I suspect while it could be done in T-SQL (painfully and slowly :-D), a CLR function built around your C++ would probably be a better option.

    Here's a link to a python version Eirikur