String to hex cast
Hello,
I am developing an application that talks to a modbus server. Let's say that I build the following command as a string:
0038 0000 0006 FF01 0000 0000
Now I need to change the type of this string from ascii to hex before I send it to the server. How do I do this without changing the actual values??
Does anyone have insight??
Thanks,
Eric
I am developing an application that talks to a modbus
server. Let's say that I build the following command
as a string:
0038 0000 0006 FF01 0000 0000
Now I need to change the type of this string from
ascii to hex before I send it to the server. How do I
do this without changing the actual values??From the above it appears that each "value" will be decoded and sent in two-byte blocks. Hence, get the short value from each part of the string using the java.lang.Short class.
e.g.
short s1 = Short.parseShort("0038", 16);
short s2 = Short.parseShort("0000", 16);
// and so on for each part of the command.
Then send each of the short's to the server.
Regards,
Bhaveet
Similar Messages
-
Hi,
I am writing an algorithm that first encrypts a String, and then converts that String to Hex String. I can successfully parse Hex Strings into Ascii Strings and vice versa, but when I encrypt I cannot do this anymore. Is there a way to convert a non-ascii character to Hexadecimal and vice versa?
Thanks in advanceMaybe so....
The encrypted value when printed does not format on my screen, and appears as boxes and such.
The values that I am passing in are a very simple encryption....XOR against a key. Here is that algorithm.
public byte[] encrypt(byte[] value) {
byte[] encrypted = new byte[value.length];
byte[] adjustedKey = getKey();
while (adjustedKey.length < encrypted.length) {
String temp = new String(adjustedKey) + new String(key);
adjustedKey = temp.getBytes();
for (int i = 0; i < value.length; i++) {
encrypted[i] = (byte)(adjustedKey[i] ^ value);
return encrypted;
Since this is an XOR, I can use the same method to decrypt as well. This is what produces my non-Ascii characters.
Is there a way for me to get the byte value of a 1 digit hex value then? this may help some. -
How can I convert a string of hex values to a hex format string programatically?
Is there a way to convert a string of the following format:
1400010107070D0305006A01 ........ ("Normal display" string)
programatically to:
1400 0101 0707 0D03 05006A01 .......... ("Hex display" striing)
I need to do this in order to calculate a CRC16 value.
See attached VIs
Thank you.
Solved!
Go to Solution.
Attachments:
CMM_SN_MULTI.vi 50 KB
CMM_CRC16_Calculator.vi 23 KBYou can iterate over the string and use the String to Hex VI. If you work with two bytes of the string at a time you can get a U8 array of the desired binary values. Then when you are complete you can either work with the byte array of convert it back to a string using Byte Array to String.
EDIT: GerdW typed faster than I did.
Message Edited by Mark Yedinak on 03-18-2010 02:55 PM
Mark Yedinak
"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot -
Hi,
Please help me to understand why this error comes.
I have deployed ear file into glass fish server.
Using adf essential in Jdevelepor 11.1.2.3.0.
[#|2012-12-04T19:17:51.658+0530|INFO|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=21;_ThreadName=Thread-2;|PWC1412: WebModule[null] ServletContext.log():JspServlet error: Servlet unable to dispatch to the following requested page: The following exception occurred:java.lang.ClassCastException: java.lang.String cannot be cast to oracle.adf.view.rich.model.RegionModel|#]
[#|2012-12-04T19:17:51.658+0530|INFO|glassfish3.1.2|oracle.j2ee.jsp|_ThreadID=21;_ThreadName=Thread-2;|unable to dispatch JSP page: The following exception occurred:.
java.lang.ClassCastException: java.lang.String cannot be cast to oracle.adf.view.rich.model.RegionModel
at oracle.adf.view.rich.component.fragment.UIXRegion.getValue(UIXRegion.java:1587)
at oracle.adf.view.rich.component.fragment.UIXRegion.getRegionModel(UIXRegion.java:415)
at oracle.adfinternal.view.faces.taglib.region.RegionTag.doStartTag(RegionTag.java:107)
at oracle.jsp.runtime.tree.OracleJspBodyTagNode.executeHandler(OracleJspBodyTagNode.java:50)
at oracle.jsp.runtime.tree.OracleJspCustomTagNode.execute(OracleJspCustomTagNode.java:261)
at oracle.jsp.runtime.tree.OracleJspClassicTagNode.evalBody(OracleJspClassicTagNode.java:87)
at oracle.jsp.runtime.tree.OracleJspIterationTagNode.executeHandler(OracleJspIterationTagNode.java:45)
at oracle.jsp.runtime.tree.OracleJspCustomTagNode.execute(OracleJspCustomTagNode.java:261)
at oracle.jsp.runtime.tree.OracleJspClassicTagNode.evalBody(OracleJspClassicTagNode.java:87)
at oracle.jsp.runtime.tree.OracleJspBodyTagNode.executeHandler(OracleJspBodyTagNode.java:58)
at oracle.jsp.runtime.tree.OracleJspCustomTagNode.execute(OracleJspCustomTagNode.java:261)
Thanks for the help in advance..It seems you have used a taskflow on a page and one of the binding.
It will be easy to point out if you paste the code of region tag *<af:region.......*. -
BIG ASCII string to HEX string
Hello guys,
I know that is already a lot of posts regarding this issue, but I couldn't find exactly what I need and also couldn't manage to solve it myself...
I need to convert a string with ASCII characters to a string containing HEX representation of these characters.
What I did was:
Apparently it works very well, but only for a limited numbers of characters, defined by data representation of the 0 constant (U64). It allows me to convert only 8 ASCII characters, as you can see on the image below:
So, it converted from 0 to 7, but not the remaining characters (8 and 9).
Any ideas??
Thanks in advance!
What is the data type of the constant wired into the typecast. My guess is it is a U64. So it will only typecast the first 8 bytes of your string to a number, then you are doing hex on those 8 numbers.
Use the function String to Byte Array. Or you could also typecast where an array of U8 integers is wired into the typecast function. -
Convers ascii string to hex string
I need to send a hex string such as 5051525354A5A6A7A8A9 to a DSP across a serial port. The string is read in from a file.
When I send this string to the DSP, it does not recognize the correct hex values.
If I enter the hex value, 5051525354A5A6A7A8A9, in to a string control that is set to hex display and then change the control to normal display, I get PQRST¥¦§¨©. When I send this string, PQRST¥¦§¨©, to the DSP, it recognizes the correct hex values.
How can I change the hex string read from the text file to this type of ASCII character conversion? I've used type cast and the other functions available in LabVIEW with no success.
This is only one of many strings I need to send so I don't want to hard code PQRST¥¦§¨© or some such string for each message.Here's a slightly simpler way.
Message Edited by altenbach on 08-23-2007 12:17 PM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
HexStringtoBinaryString.png 10 KB
HexStringtoBinaryString.vi 11 KB -
Convert HEX String into HEX Array
Hi!
Probably a silly question, but I am looking for a way to convert a ROM ID number such as "5E03C21000BA" into an short hexadecimal array.
The way to do this in C would probably be
char[17] str_romID = "5E03C21000BA";
uchar[8] romID;
sscanf(str_romID, "%02X%02X%02X%02X%02X%02X%02X%02X",
&romID[0], &romID[1], &romID[2], &romID[3],
&romID[4], &romID[5], &romID[6], &romID[7]);
but I can't seem to find a way to do this in LabVIEW. I would be very grateful if you could help me out with a sample program. Thanks ever so much!
StefanHello Blondchen,
I have attached a picture to my last explanation. This example doesn't take care of strings with an uneven number of chars!
My array has only 6 numbers as you only gave a string with 12 chars... That's what I asked before: how should we know where to split your string to the single numbers? Normally I would take 2 chars to form a byte (as I did in the example). If you give me 16 chars I give you 8 bytes...
I also think your C byte array will be an U8 array in LabView. If you REALLY need I8 numbers you can change the default type of the "hex to string" or cast to I8 (advanced->data manipulation->type cast) after the conversion.
Best regards,
GerdW
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome
Attachments:
ConvertHexHex.png 13 KB -
How to convert a string to hex in TestStand
Hi everyone, I think this is a fairly easy question to answer but I am newer to TestStand.
In one step I am pulling in the Serial Number of a Device (which is alpha and numeric characters) and storing it as a String Local called Local.SerialNumberString. In the following step I need to convert this Local to a Hex value and store it as Locals.SerialNumberHex
Here is the data representation I need to take place:
Locals.SerialNumberString = ABC123456
and would like to know of a function that would convert to the following:
Locals.SerialNumberHex = 414243313233343536
How can this be done?
Thanks so much!It looks like what you are asking for is more than just converting to hex, it looks like you want to convert the characters in the string to their ascii value representation and then convert that to hex.
1) Use a for loop Locals.i = 0; Locals.i < Len(Locals.SerialNumberString); Locals.i++
2) Inside the loop do: Locals.SerialNumberHex += Str(Asc(Mid(Locals.SerialNumberString, Locals.i, 1)), "%.2x")
Hope this helps,
-Doug -
Hello,
I have a hex string that contains the address then word:
0 8E39
1 60E3
2 1B
3 42
4 100
5 0
I am trying to generate two arrays, one with the address in two bytes and the other with the word in four bytes so that I will end up:
00 8E39
01 60E3
02 001B
03 0042
04 0100
05 0000
Any help will be greatly appreciated!
Thanks,
hiNi.
Solved!
Go to Solution.
Attachments:
hex_word_with_addr.txt 1 KB
string to array.vi 13 KBYou can also directly use "read from spreadsheet file" (but you need to convert to U16 later).
hiNI wrote:
I am trying to generate two arrays, one with the address in two bytes and the other with the word in four bytes so that I will end up:
You said you wanted two arrays, so you still need to slice out the two columns.
LabVIEW Champion . Do more with less code and in less time .
Attachments:
string to arrayMOD.vi 17 KB
stringToArrayMOD.png 28 KB -
How to convert EBCDIC String in hex to unicode?
How do I convert, for example, "C1C2C3C4C5" (EBCDIC in hex) to "ABCDE"? The input and output types are both String. Thanks in advance!
1. Create a String of 256 characters, where the index corresponds to the ASCII character (e.g. character at index 193 (0xC1) would be 'A').
2. Parse your input string two characters at a time using Integer.parseInt(s, 16) to convert the two digits to a number, and use the resulting number to get the equivalent ASCII character from the translation string in step 1, which can be appended to your output. -
Hello Everyone:
I'm trying to connect to a local system which needs byte streams... Then I use byte arrays as follows:
final byte[] LOGIN = {(byte)0x31, (byte)0x36, (byte)0x37, (byte)0x38}};
In Ascii Code it means "1678".
I have no problem with this, the real problem is that I need to transform a String entered by the app. user into bytes (the Ascii code), I tried to cast the chars with <<(byte)'c'>>, but it doesn't work.
What I should do?
Thanks.
JogomI have no problem with this, the real problem is that
I need to transform a String entered by the app. user
into bytes (the Ascii code), I tried to cast the chars
with <<(byte)'c'>>, but it doesn't work.(byte) 'c' works for me. I get a byte value of 99, which is exactly what I expect. How does it not work for you? -
Hello
I've got following question: I have a STRING of bits e.g. "01001010". Is there any function to convert it to Hex - code?See the attached code. I wasn't sure by what you meant by a "STRING of bits" so it shows two different things.
Remember also that the distinctions between binary, decimal and hex are only significant to human beings reading the numbers--computers don't really care. An unsigned 8-bit value is an unsigned 8-bit value, regardless of how it's represented for human consumption.
Note that in a array the LSB is the first element. In a string, the LSB is the far right-hand digit.
Mike...
Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion
"... after all, He's not a tame lion..."
Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps
Attachments:
formatting.vi 18 KB -
How to convert noraml string to hexa string in teststand
Hi,
I need to send RS232 command in hexa format (type - string), but in teststand it is taking as ASCII characters.
Tried in Labview, working fine, but in teststand i m facing difficult.
Please help !
Thank youHere you are,
Locals.strHex = Str(Locals.u64_Val,"%x")
Regards
Juergen
=s=i=g=n=a=t=u=r=e= Click on the Star and see what happens :-) =s=i=g=n=a=t=u=r=e=
Attachments:
ToHex.seq 5 KB -
Convertin string in hex number
Hi all
I must convert an keyboard input (i.e. F012AC14) to an hex: F0, 12, AC, 14.
From a keyboard I'm reading a String (is correct?) and then with a for loop I'm suddivide a string into F0, 12, AC, 14, but I'm not able to convert a string F0 to an hex 0xF0, 12 to an 0x12 ecc for use in aritmetichal operations.
Could you help me?
Thanksuse this method with radix 16
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Integer.html#parseInt(java.lang.String, int) -
Simple way to turn string to hex
Hello...
I was wondering if there would be nice way to get string, rather long one I might add, to hex form for mobile phone purposes... Preferably to string if possible.
I have looked through forums and have tried to find a nice solution but can't.To Hex String:
final String nonHexString = "Hello from YoGee";
System.out.print("0x");
for (int i = 0; i < nonHexString.length(); i++) {
System.out.print(Integer.toHexString(nonHexString.charAt(i)));
}Back again:
final String hexString = "0x48656c6c6f2066726f6d20596f476565";
int length = hexString.length();
String[] temp = new String[(length - 2) / 2];
int counter = 2;
for(int i = 1; i < ((length - 2) / 2) +1; i++){
temp[i-1]= hexString.substring(counter,counter+2);
counter = counter + 2;
char[] chars = new char[temp.length];
for(int i = 0; i < temp.length; i++){
chars[i] = (char) Integer.parseInt(temp, 16);
System.out.println(new String(chars));
Maybe you are looking for
-
Meet a problem of data exchange for sale order from CRM to R3.
Dear Friends: I do the data exchange for sale oder from to R3 today , the problem's detail is as follows: When i save a sale order in CRM (Version is 5.0) . it can automatically generate a bdoc which bdoc type is BUS_TRANS_MSG. but the bd
-
Using Powermac G5 for Video playback on TV, Best options?
Have a Powermac G5 Dual 2Ghz '03 with 8gb Ram and an ATI 9600 Pro 256MB dual DVI wanted to playback my files of .mpeg and ,avi movies on my TV used an Apple DVI to S-video cable and did not work. I am using an HP 24" LCD Monitor running at 1900X1200
-
How to get space between two values in a single cell of a table.
hello, how to get space between two values in a single cell of a table. thanks a lot. kailash.
-
Dear Expert, Is it right to create the equipment of subequipment if we do like this,can you explain the advantages and disadvantages for the same.Kindly give some cases where you have to structre this kind of scenerio. RC Edited by: Raju Chauhan on N
-
In SQL Server Transactional replication what all changes I can do on subscriber table
In SQL Server Transactional replication what changes I can do on subscriber table Thanks