Is there any good way convert a binary (base 2) strings to integers in T-SQL (if not I guess I can write a function…)
‘0110’ => 6 etc.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Do you know that the strings will always be a particular length? If so you could hard-code a bunch of Substring/convert-to-int/multiply steps. It wouldn’t exactly be nice though…
EDIT: To give a bit more detail, suppose you know it’s going to be length 4, you could do:
Apologies if the syntax is slightly off.
Unpleasant, and doesn’t work in the more general case (where you’d basically need to loop in some form) but it might be good enough for a quick fix.
(If downvoters could please add comments, it would be much appreciated. T-SQL is somewhat outside my realm of expertise – explanations of why this is a bad idea are much more helpful than just the downvote to indicate that it is a bad idea.)