Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Semrush - keyword research tool

Linux Foundation Training and Certification

Disclosure: My content contains affiliate links.

33,433 questions

43,814 answers

573 users

How to parse a string of hex and print the int and char for each hex value in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string hex_s = "6A 20 6C 48 6F 59 92 41";
                string[] hex_arr = hex_s.Split(' ');

                foreach (String hex in hex_arr)
                {
                    int n = Convert.ToInt32(hex, 16);
                    char ch = (char)n;
                    Console.WriteLine("hex = {0} : int = {1} : char = {2}", hex, n, ch);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:
  
hex = 6A : int = 106 : char = j
hex = 20 : int = 32 : char =
hex = 6C : int = 108 : char = l
hex = 48 : int = 72 : char = H
hex = 6F : int = 111 : char = o
hex = 59 : int = 89 : char = Y
hex = 92 : int = 146 : char = ?
hex = 41 : int = 65 : char = A
 
*/


Learn & Practice Python
with the most comprehensive set of 13 hands-on online Python courses
Start now


answered Mar 26, 2015 by avibootz

Related questions

1 answer 134 views
1 answer 111 views
1 answer 100 views
1 answer 38 views
...