473,323 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Hex to ASCII conversion issue

I have 32 byte of hex data to be converted in to ASCII..the data is "f230810108C080182020202004202028". while sending it to the server end it changes to "3f 30 3f 01 08 3f 3f 18 20 20 20 20 04 20 20 28" and then converts to ASCII. hence i am not getting proper response from the server. I noticed that the hex pair like "F2" changes to "3F" means if the MSB is "1" then that pair is changed. any suggestion on this. please help.
Jun 30 '11 #1
3 3436
mac11
256 100+
Do you have a code sample? There may be a simple solution but we can't see what's going on yet.
Jun 30 '11 #2
nbiswas
149 100+
You can try this

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4.  
  5. namespace ConsoleApplication1
  6. {
  7.     class Program
  8.     {      
  9.         static void Main(string[] args)
  10.         {
  11.             Console.WriteLine(Encoding.ASCII.GetString(Hex2Byte("f230810108C080182020202004202028")));
  12.             Console.ReadKey(true);
  13.         }
  14.         public static byte[] Hex2Byte(string hex)
  15.         {           
  16.             byte[] bytes = new byte[hex.Length / 2];
  17.             Enumerable.Range(0, bytes.Length).ToList().ForEach(i => bytes[i] = Convert.ToByte(hex.Substring(i * 2, 2), 16));
  18.             return bytes;            
  19.         }
  20.     }
  21. }

Let me know in case of any concern
Jul 4 '11 #3
Plater
7,872 Expert 4TB
If you have a byte[] you can just do something like this:
Expand|Select|Wrap|Line Numbers
  1. private static string bytesToASCIIHex(byte[] buff)
  2. {
  3.   StringBuilder retval = new StringBuilder();
  4.   foreach (byte b in buff)
  5.   {
  6.     retval.AppendFormat("{0} ", ((int)b).ToString("X2"));
  7.   }
  8.   return retval.ToString().Trim();
  9. }
  10.  
Jul 6 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Christophe Poucet | last post by:
Hellom I have an issue with implicit conversions. Apparently when one calls an operator on a class Y which has a conversion operator to class X which has the operator . Sadly it will not do...
3
by: Scott | last post by:
I am using DB2 Connect on HP-UX 11i to read data from an AS400 using SQL. DB2 Connect is converting a vertical bar (¦) character to this: ª. Please see the example below. I have tried changing the...
4
by: objectref | last post by:
hi to all, i just need to convert a hex string, let's say "00" or "16" or "FF" that i get from a file and display the ascii character equivalent. How i can do this ?? thanks a lot form any...
7
by: Zach | last post by:
Can one convert Unicode to ASCII? If so, could you please give an example? Many thanks.
0
by: Oscar Thornell | last post by:
Hi, I have run into a VS.NET 2005 conversion issue. As a starter (before I go for production code) I tried to convert the well known Portal starter kit that can be downloaded from http://asp.net...
1
by: Aparna Sinha via .NET 247 | last post by:
Dear All, How do we get ascii equivalent of any character in C#.Please give a C# example with relevant name spaces.. -------------------------------- From: Aparna Sinha -----------------------...
3
by: LS | last post by:
I use winpcap in dotnet to capture packets from the wire. I have them in a byte() array. (variable rawbytes()) How do I convert them to a readable string? I have for example following values...
0
by: Jon Paal | last post by:
text entered as ascii in a text box as "•" is converted to "•" how do I stop the conversion of the ampersand ?
3
by: AlekseyUS | last post by:
Hi All, I'm writing a program, part of which needs to read text from a .log file in UNICODE line by line, then convert it to ASCII and write it to an ASCII .log file line by line... I've been...
1
by: Vic | last post by:
I have a c program which writes mac address entries onto a text file. Text file when opened in vim looks like this index mac 1 ^@^@^Q^@^@^A ascii of (00.00.11.00.00.01) 2 ^@^@^Q^@^@^B...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.