willsherwood
asked on
MySQL STRING functions for BINARY formatting
I want to display a 32-bit integer as binary, but formatted to have a space every 4 chars.
I assume we start with BIN(FieldName), but what's the best way to insert spaces (or commas) every fourth resulting character?
INSERT? REGEX?
thanks!
I assume we start with BIN(FieldName), but what's the best way to insert spaces (or commas) every fourth resulting character?
INSERT? REGEX?
thanks!
Do you have a programming language to work with, eg PHP? The formatting part is probably more easily done through something other than MySQL
ASKER
yes but this is a "phrase" that goes into an app that generates PHP&MySQL code.
Thus it needs to be encapsulated (albeit lengthy!) for a SELECT query.
i understand PHP would be easier, but really need it in MySQL.
There are brute force strategies to mask&shift for each 4 bits to display, but i was hoping for a clever REGEX or other tricky way :)
I could even do four groups of 8 bits, if the code is really ugly.
thanks
Thus it needs to be encapsulated (albeit lengthy!) for a SELECT query.
i understand PHP would be easier, but really need it in MySQL.
There are brute force strategies to mask&shift for each 4 bits to display, but i was hoping for a clever REGEX or other tricky way :)
I could even do four groups of 8 bits, if the code is really ugly.
thanks
ASKER
... or maybe it's just a series of
CONCAT(
LEFT(BIN(FieldName),4),' ',
MID(BIN(FieldName),5,4),' ',
...
)
CONCAT(
LEFT(BIN(FieldName),4),' ',
MID(BIN(FieldName),5,4),' ',
...
)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.