Solved

MySQL STRING functions for BINARY formatting

Posted on 2011-02-21
4
261 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 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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access - need to reduce row size 25 76
Complex SQL statement in VB.NET 7 45
Optimize the query 5 65
reverse engineer .sql from php files 11 65
This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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