From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
07-19-2013 07:27 AM
I need to pad a string with zero's on the left. Example: 2 would be 002, 4F would be 04F. I am trying to pad just a string, I am using format string and tried %03x but this does not work. Any suggestions?
Solved! Go to Solution.
07-19-2013 07:28 AM
Try the concatenate string function. You can use the string length function to determine how many zeros you need to pad with...
Strokes
07-19-2013 07:47 AM - edited 07-19-2013 07:58 AM
The simplest way that comes to mind is to use a for-loop to iterate and concatenate zeros for each "empty space" calculated by Final String Length - Input String Length. Then concatenate this with the original string.
For example, here is something I wrote real quick. There is probably a more elegant solution, but this should be a good starting point:
PadZeros.VI
EDIT:
The above doesn't care what the original input string is. If you want one more specific to hexadecimal, then you can use something with Format Into String:
Padded Hex.vi
The important part of this VI is the format string of "%03x". The first "0" says to pad the input with zeroes. The "3" tells you the length of the final string (any strings smaller than that length will get 0 characters to pad it to the requested length). The "x" tells you it's in hex.
EDIT 2:
The reason "%03x" doesn't worth with String data type inputs is because by default the Format Into String with String data type uses %0 to denote padded spaces. Either convert your string into a numeric datatype and use the format, or else just use a for-loop as I originally suggested.
07-19-2013 07:47 AM
Attached is the circuit I have so far. Essentially what I need is a number that is between 0-4095 (0-FFF in hex) to be converted to a hex number holding 3 places.
Example:
4 --> 004
12 --> 00C
4095 --> FFF
07-19-2013 07:54 AM - edited 07-19-2013 07:55 AM
07-19-2013 07:55 AM
Thanks! That was exactly what I needed!
07-19-2013 07:55 AM
First of all, it is better to attach your actual VIs. It is a lot easier to debug that way.
Your program doesn't make any sense. Your rolling number is an integer, yet you expect to get a floating point out of it.
All you really need is the Format String with the format being %04x and have your rolling number as the input.
07-19-2013 11:43 AM - edited 07-19-2013 11:44 AM
@ncm wrote:
Thanks! That was exactly what I needed!
What was exactly what you needed? You should mark the post that helped you as the solution (and, liberally give kudos) so that future visitors to this thread can see what answered your question.
07-19-2013 11:54 AM - edited 07-19-2013 11:54 AM
@jcarmody wrote:
@ncm wrote:
Thanks! That was exactly what I needed!
What was exactly what you needed? You should mark the post that helped you as the solution (and, liberally give kudos) so that future visitors to this thread can see what answered your question.
You're a little late to the party my friend. He already accepted my solution and gave Kudos haha. I don't think he is as clueless about the NI Forums as you seem to be suggesting. 😉
To clarify, he asked in his OP regarding why "%03x" did not format a hexadecimal string to be padded with zeros, but rather, padded with spaces. I address this above and give him two possible solutions.
07-19-2013 12:42 PM - edited 07-19-2013 12:47 PM
@jcarmody wrote:
I must be missing something [...]
Indeed, I certainly was.
@MrHappyAsthma wrote:
[...]
You're a little late to the party my friend. He already accepted my solution and gave Kudos haha. I don't think he is as clueless about the NI Forums as you seem to be suggesting. 😉
[...]
Now that I actually read your entire post I see that I was out of line. Even though his post immediately before mine, with the attached block diagram not containing any of your suggestions (even after marking it as the solution) seems to indicate that he was still having trouble, I apologize to you and ncm, offer kudos of my own as propitiation, and repent in sackcloth and ashes.
🙂