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'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
So in the interest of practicing Python and more specifically understanding object oriented programing
I'm practicing for the upcoming ACM programming competition in a week and I've gotten
While practicing the jxl API, i cant extract details from certain Excel sheet its
While practicing different scenarios in which CSS3 pseudo-classes and selectors might come in handy,
I am practicing using pointers. I have a pointer to an array of 3
I am practicing for an exam, and found a sample problem that gets me
I'm practicing with Ruby and regex to delete certain unwanted characters. For example: input
I am practicing over the summer to try and get better and I am

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.