[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

MySQL STRING functions for BINARY formatting

Posted on 2011-02-21
4
Medium Priority
?
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 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