Labview converting hexformatted string to ascii - labview

In labview I am trying to convert a hex string to ascii format. For example if I have a hexstring like: 09124E4F21CD0024FFFFFFFFFFFFFFFF the ascii version of this is : NO!Í or basically a bunch of illegible symbols. I tried using the labview functions of converting hexstring to number but they didn't work. How would I convert the ascii part to hexformatted ascii?

Hexadecimal String to Number works fine, but only for a hex string that represents a number that can be stored as a numeric data type:
If the input string represents a number outside the range of the
representation of number, number is set to the maximum value for that
data type.
Your example input is 128 bits long whereas the longest integer data type in current LabVIEW is 64 bits.
You can use this function, but you need to convert the input one byte at a time:
Create a While Loop and add a shift register. Initialise the shift register with your input string.
Inside the loop, wire the string from the shift register to the string input of a Search/Split String function
Wire a numeric constant of 2 to the offset input - i.e. split the string into the first two characters, and the rest
Wire the match + rest of string output to the right-hand shift register terminal
Wire the substring before match output to a Hexadecimal String to Number function
Wire the default input of this function to a numeric constant with value 0 and type U8
Wire the output of this function to the right-hand side of the While loop and make the terminal indexing (via right-click)
Use an Empty String/Path? function to exit the While loop when the string being passed back into the shift register is empty.
The output from the indexing terminal you created will now be a U8 (byte) array containing the data converted from the input string. If you want it in string form you can convert it using Byte Array to String.
This assumes that your input string is always a multiple of 2 characters in length. If you need it to handle an input such as "3F2" you'll need to check for this and do something to the input (I'll let you figure out what) before passing it into your loop.

Related

SAS: Why does the input function convert from character to numeric, and the put function convert from numeric to character?

SAS documentation defines the input and put functions as:
Input function: Returns the value that is produced when SAS converts an expression using the specified informat
Put function: Returns a value using a specified format.
So the input function takes the variable and an informat as arguments, while the put functions takes the variable and a format as arguments, right?
If that is the case, why is the input function used to convert a variable from character to numeric, while the put function is used to convert a variable from numeric to character?
Are the input and put functions more tied to informats and formats, respectively, as opposed to character to numeric and numeric to character conversions, respectively?
Also, what is the difference between the input and put functions and the input and put statements?
The last question answers the first one. It is easiest to think of the PUT() function and INPUT() function in terms of how the PUT and INPUT statements work.
The PUT statement is for printing data into a text file report. You can print numeric or character variables but you are always writing character strings. The INPUT statement is for reading data from a text file. You can read into numeric or character variables but you are always reading from character strings.

Convert 4 Byte String Array of Hex to Decimal

I am trying to convert a string of 4 bytes in a string to an integer number in LabView, currently I am using the string subset to break apart my string and then storing it into a String Indicator on the front panel, however, I need to convert that string to an int so I can show the decimal value as well as convert it from inches to mm. Here is what I'm doing now:
I've tried converting to double using the convert string to double functions as well as I've tried splitting it up using the index array...can't quite seem to get an int out ever. Thanks!
Do as Ton Plomp said and use the Scan From String block. However, in yours, you don't want to separate with commas and with spaces. Just do:
%x%x%x%x
And that should do it for ya. Don't forget to pull the scan down so you have 4 outputs.
You can use Scan from string with the following format string:
%x
You can expand the scan from string to scan multiple items at once.

Binary file output for fixed length string

I am trying to write a binary file which also has a string which i want to have as fixed length in vb.net. I tried lset, padleft in debug, the value returned is correct but in the output file, the first character before the string is the fixed length i specified. why does the binary writer write the additional char ?
I found out that if if you don't want or need the length byte you can call Write with a Char [] array instead of a String

standard keyboard character not included in Base64?

I have a function that generates a random Base64 String
Public Shared Function GenerateSalt() As String
Dim rng As RNGCryptoServiceProvider = New RNGCryptoServiceProvider
Dim buff(94) As Byte
rng.GetBytes(buff)
Return Convert.ToBase64String(buff)
End Function
This will always return a 128 Character String. I then take that string and divide it into 4 substrings. I then merge that all back into one big string called MasterSalt like so
MasterSalt = (Salt.Substring(1,32)) + "©" + (Salt.Substring(32,32)) + "©" + etc...
I am doing this because I then put all of this into an array and say Split(MasterSalt, "©")
My concern is I am not overly confident in the stability of using "©" as the delimiter to define where the string should be split. However I have to use something that is not going to be included in the randomly generated base64string. I would like it to be something that can be found on a standard keyboard if possible. So to be clear my question is: is there a glyph or character on a standard keyboard that would never be included in a randomly generated base64string??
Base64 uses 64 characters to encode 6 bits of the content at a time as values 0-63;
A-Z (0-25)
a-z (26-51)
0-9 (52-61)
+ (62)
/ (63)
...and it uses = as filler at the end if required.
Any other character will be available for you to use as a delimiter, for example space, period and minus.

How can you format the result of a formula as s number

I'm using a formula in Excel 2007 to grab a mailbox size from a string. I'm stripping out all of the text before and after, and removing the , characters, yet Excel will not format the result as a number.
Because of this, I can't run any statistics such as total size or average size.
=SUBSTITUTE(MID(MailboxEX01[[#This Row],[TotalItemSize]], FIND("(", MailboxEX01[[#This Row],[TotalItemSize]]) + 1, FIND("bytes", MailboxEX01[[#This Row],[TotalItemSize]]) - (FIND("(", MailboxEX01[[#This Row],[TotalItemSize]]) + 2)), ",", "")
I tried =TEXT({the above}, "#,##0"), which successfully added the , character as the thousands separator, but (I guess unsurprisingly) still failed to format the cell as a number.
Does anybody know how I can force the result in this cell to format as a number? Thanks.
Your formula takes text values, strips stuff out, and replaces stuff. But the result is still text. If the result of that formula contains only the characters 0 to 9, you can coerce it into a number by using
={your formula}+0
or
={your formula}*1
or
=--({your formula})
Using =TEXT({your formula}, "format") will not produce a number. The TEXT() function returns text, as the name implies.
But if you use a mathematical operator on a number that is stored as text (or a text that represents a number), the maths operation will coerce that text value into a real number. The third suggestion uses the double unary (Google that) to coerce the text into a number.