Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5967169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:54:19+00:00 2026-05-22T19:54:19+00:00

I am practicing StringToByteArray() on VS2005. But throw exception. Could you please tell me

  • 0

I am practicing StringToByteArray() on VS2005. But throw exception. Could you please tell me more information about it?

Exception alert **An unhandled exception of type ‘System.FormatException’ occurred in mscorlib.dll

Additional information: Could not find any recognizable digits.**

public static byte[] StringToByteArray(String hex)
    {
        int NumberChars = hex.Length;
        byte[] bytes = new byte[NumberChars / 2];
        for (int i = 0; i < NumberChars; i += 2)
            // exception here
            bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
        return bytes;
    }

    static void Main()
    {
            byte[] myByte = new byte[2];
        myByte = StringToByteArray("0x0");
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:54:19+00:00Added an answer on May 22, 2026 at 7:54 pm

    You either need to drop the “0x” from the start of the string you pass in, or start your for loop with int i = 2;. Also you’re allocating the array in your method. You don’t need to do it Main as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was practicing some multithreaded programs, but I could not figure the logic behind
I am practicing the exercises from my textbook but I could not get the
For practicing purposes, I’m about to create a new ASP.NET MVC 3.0 application. My
Been practicing with those system calls, but I stucked into this code: #include <stdio.h>
I am practicing with PHP and AJAX but I have some problems! I'm trying
I'm practicing with the Key Value Observing, but it's something I do not quite
I've Been practicing some CSS By making some rollover buttons, and using -webkit but
I am practicing to generate the star in the following result, but I was
i'm practicing c and looking to use visual studio. but can I write console
so im practicing the STL string class, but i can not figure out why

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.