I want to convert a string of hex characters (2 hex chars = 1 byte), to ASCII. Hex chars include zeros (0x00) as well, which I want to include in ASCII string.
hex string: 5000005355....
ASCII: P<null><null>SU...
I can do it and the string length also includes nulls but when I concatenate other string, it doesn't show as its part. -
string HexValue = "500000535500";
-
string StrValue = "";
-
while (HexValue.Length > 0)
-
{
-
StrValue += System.Convert.ToChar(System.Convert.ToUInt32(HexValue.Substring(0, 2), 16)).ToString();
-
HexValue = HexValue.Substring(2, HexValue.Length - 2);
-
}
-
StrValue += "hello";
-
textASCII.Text = StrValue;
-
MessageBox.Show(StrValue.Length.ToString());
-
Or .. is there some problem with the text field in which I am displaying the result?
Actually, I need to send the string containing nulls through socket.
12 4897
Put a breakpoint in after the concatenate and check the actual value of your variable. I wouldn't be surprises if it was complete but displaying wrong. Strings often don't deal well with having nulls in them. Null termination is fairly standard so when a control reaches the null it may just stop looking.
Why would you convert it to a string if you were going to send it on a socket?
@tlhintoq
In the tooltip, it shows the string with nulls and "hello" at the end, but in 'quick watch' window, it shows only characters before first '\0' and no "hello"...
Well tlhintoq really WAS right, \0 is not a valid character in an ASCII string and is used for termination. Its just part of the language specs.
If you really want to see the whole string, look at it in hex
@Plater
I have to convert because I want it to be read on the receiver end as it is in hex at my end, if I send it in hex form, it shows up as numerics on the other end.
If I send 5000005355, it becomes 35303030303035333535, i-e '5' converted to ASCII (0x35), and so on ...
But I want to send 5000005355 as 5000005355, which is only possible by converting them in ASCII form, 'P' would be taken as 0x50, <null> as 0x00 and so on ...
You could convert them to bytes and send them as bytes.
Sockets use bytes to send the data, you would have to convert the string to bytes to send it anyway
@Plater
Convert the hex string to bytes or the ASCII? How?
so you have a literal string such as
string s = "5000005355" ?
How do you get this string?
I mean byte b= 0x50 is the first byte and
byte[] ba = new byte[]{0x50, 0x00, 0x00, 0x53, 0x55}; would be the byte array of it
@Plater
The hex string is created at runtime so I cannot assign byte array like this.
So someone types into a box "5000005355" or something?
And even if created at runtime, you can still parse into byte[]
@vekipeki
Thanks! ... to all for their quick response.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: David Lawson |
last post by:
I know how to conver a string to an array of strings, but I need to convert an ascii string to an
array of integers (really unsigned chars). Eg,
$str ="ABC";
needs to convert to something...
|
by: craig.wagner |
last post by:
I've got an application that is calling a command-line executable. The
command-line tool uses stdin and stdout as its interface, and it
expects a binary stream in and sends a binary stream out.
...
|
by: Jonathan Burd |
last post by:
Greetings everyone,
Here is a random string generator I wrote for an application
and I'm wondering about the thread-safety of this function.
I was told using static and global variables cause...
|
by: MilanB |
last post by:
Hello
How to convert char to int?
Thanks
|
by: comp.lang.tcl |
last post by:
I have a TCL proc that needs to convert what might be a list into a
string to read
consider this:
]; # OUTPUTS Hello World which
is fine for PHP
]; # OUTPUT {{-Hello}}
World, which PHP...
|
by: Joris De Groote |
last post by:
Hi,
I have a 1 dimensional table byte with a number af characters in ASCII code.
How do I convert those ASCII codes to real letters?
Thanks
|
by: Zach |
last post by:
Hello,
This might be a rather basic question, but I've tried a few things and
I can't really find a solution as elegant as what I'd like for this
problem. The situation is this - I have a file...
|
by: meendar |
last post by:
Hi,
I am having a character pointer which contains ascii values. i just
want to convert all these ascii values to respective characters and
again store it in another character pointer.
...
|
by: Michael Postmann |
last post by:
Hello!
I have Oracle 10g using AL32UTF8 as internal charset.
I have a documents table where uploaded files (I'm using modplsql
web-gateway (release 8i)) are stored in a blob-column. I upload a...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| | |