Solved

MySQL STRING functions for BINARY formatting

Posted on 2011-02-21
4
258 Views
Last Modified: 2012-06-21
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!
0
Comment
Question by:willsherwood
  • 2
  • 2
4 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34947385
Do you have a programming language to work with, eg PHP? The formatting part is probably more easily done through something other than MySQL
0
 

Author Comment

by:willsherwood
ID: 34947623
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
0
 

Author Comment

by:willsherwood
ID: 34947654
... or maybe it's just a series of  
CONCAT(
   LEFT(BIN(FieldName),4),' ',
   MID(BIN(FieldName),5,4),' ',
     ...
   )
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 34990179
I think that's probably the best you can do. Regular expressions in MySQL are only capable of saying "yes that matches" or "no it doesn't".
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question