Skip to content
Advertisement

How to convert Base64 to a comma separated binary

I’m modifying the explaination so its clearer.

I had this data in an image column within sql server.

I used then used this query to get these results

And using online converters i can get it to a binary/commma separated list.

From here i need to convert each 8bit word into a decimal.

The new list doesn’t need to show the original 8 bits. Its only there for more detail

Where i am struggling is how to convert it natively within SQL since this is a fairly large table. My attempts have been a bunch of flops and i have hit a mental block. Any help is appreciated.

—–update—–

so what i have learnt is that i have is a hex string of comma separated values that need converted to their integer equivalent. I have tried to convert hex to in but it appears to be trying to convert the entire string at once.

results in

How do I parse the hex first then do the conversion??

Advertisement

Answer

Given a string of comma-delimited binary digits, one approach is to split the string into rows to get each binary value and then convert each to an integer, then re-aggregate into a delimited string.

First it would be useful to have a function to convert to an integer, one such function could use a simple tally table to split each digit into a row and then sum the bits raised to the correct power of 2.

And then to make use of it by splitting the source string (using OpenJson to ensure correct ordering)

See Demo Fiddle

Sample data: 11010011,01000000,01110100,00000011,01001110,00111001,11010011,01000000,01111100

Output

enter image description here

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement