Bit-String to Hex
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
Similar Messages
-
Create an image from a bit String
Hi everybody
I don't know if this is the correct forum for this so first of all sorry if I did it wrong. I have never created an image in Java so I am a little bit lost with my new task.
I have a bit String (for example "00111010") and I want to create an image converting the 0-s into white pixels and 1-s into black ones. The new image should be 8x1 pixels (for the previous example would be white-white-black-black-black-white-black-white).
As I have explained before, I have never done something similar so I don't know how easy is my problem to resolve. Any help?read up on Java2D and image processing
try some tutorials
basically you need to convert your data to an intensity map
there's a couple ways to do it
i'd convert to a byte or int array which you can pass into the image constructors
try and get started then come back here when/if you have specific problems -
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 -
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. -
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 -
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,
EricI 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 -
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 -
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. -
How can you specify a string literal that compiles to an array of 16-bit units? "string" compiles to 1-byte char* and L"string" compiles to 4-byte wchar_t but we need a syntax to specify a string of 2-byte unsigned short.
I'm reasonably confident that there is no 16-bit driver that works with an 8i client. I'd suspect that the old 16-bit drivers can probably be used to connect to an 8i database from an older client.
Justin -
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 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 -
Char to bit string???
Hi everyone,
I have a small problem and I was wondering if anyone can help. I want to convert a char value to a string of bits. I have had no problem doing it with an integer but I "keep reaching for the Aspirin" when it comes to the char. Any ideas? I am sure I am doing something stupid - it should be relatively simple.Here's the general idea:private static String toBitString(char c) {
return Integer.toBinaryString(c);
private static String toFixedLengthBitString(char c) {
return Integer.toBinaryString(c | 0x10000).substring(1);
} -
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)
Maybe you are looking for
-
Using NI-IMAQ imgSnap (ANSI C) with Windows 7 x64
Hello, I am trying to perform some basic image acquisition using ANSI C calls to NI-IMAQ (as distributed by the November 2009 release of NI Vision). I am developing on Windows 7 x64. Setup seems to work fine, but when I make the following call: vo
-
Can anyone help me? My PDFs are suddenly opening in Colorsync which won't let me print them. How do I get them back to whatever was opening them before?
-
Mac mini (Mid 2010) which is better HDMI or VGA ?
I'm getting a Mac mini (Mid 2010) and a Samsung - 23" LED Monitor that has both HDMI and VGA inputs. What would be the best way to connect them ? I've only had iMacs, iBooks and a MBPRO.
-
How can I find setting with my iPad
I can't find setting and App Store how can I get
-
How to re-install my adobe CC again?
Yesterday I had a problem with my computer. It would noT open and windows made a verification of the problem but it uninstalled my Adobe InDesign CC, Photoshop and Illustrator. I went on the cloud to reinstall them but it looks like I can't. I have a