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 8868409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:15:55+00:00 2026-06-14T17:15:55+00:00

I have a requirement where I am generating a binary number from a string

  • 0

I have a requirement where I am generating a binary number from a string say “111111” and converting it to a decimal number to store in database. Each digit (ie. 1/0) from this binary number signifies different access rights of user to different modules in the application. As and when the number of modules will increase, the number of digits in this binary number will also increase. By the time when the binary number reached to the length of 64, (ie. 64 times 1s), I was able to convert it to decimal number using

Int64 dec =Convert.ToInt64(binVal,2);

And it worked fine. But when the length increased to 65, it gave an OverFlow Exception : Value was either too large or too small for a UInt64. Can anyone suggest any possible solution where I can convert this binary number of 65 length to decimal or any other form to save it in database.

Thanks in Advance.

  • 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-06-14T17:15:56+00:00Added an answer on June 14, 2026 at 5:15 pm

    To convert a binary number of length 65 or more to decimal/whatever you’ll have to write a method like this:

    public BigInteger FromBinaryString(string binary)
    {
        if (binary == null)
            throw new ArgumentNullException();
        if (!binary.All(c => c == '0' || c == '1'))
            throw new InvalidOperationException();
    
        BigInteger result = 0;
        foreach (var c in binary)
        {
            result <<= 1;
            result += (c - '0');
        }
        return result;
    }
    

    which uses System.Numerics.BigInteger structure to hold big numbers. Then you could explicitly convert it to decimal (or to a byte array) and store it in your database:

    var bigInteger = FromBinaryString("100000000000000000000000000000000000000000000000000000000000000000");
    // to decimal
    var dec = (decimal)bigInteger;
    // to byte array
    var data = bigInteger.ToByteArray();
    

    EDIT: If you’re under NET 3.5, just use decimal instead of BigInteger (also replace left-shift operator << with the multiplication operator * for decimals):

    public decimal FromBinaryString(string binary)
    {
        if (binary == null)
            throw new ArgumentNullException();
        if (!binary.All(c => c == '0' || c == '1'))
            throw new InvalidOperationException();
    
        decimal result = 0;
        foreach (var c in binary)
        {
            result *= 2;
            result += (c - '0');
        }
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a requirement to store 500 measurements per second, coming from several devices.
I have a requirement where i'm dynamically generating some rows and each row has
I have a requirement for the generation of a given number N of vectors
Hi i have requirement to process large number of files via multithreading in java.
In our project we have requirement that, after receiving sms message from third party
I have an requirement of generating two excel files at once. We are using
Let's say I have a database like this: Users ----- ID int PK Identity
I have the requirement of generating UML Diagrams for one of my C++ assignments.
I have the requirement of generating UML Diagrams for one of my C++ assignments.
I have a web application in Spring that has a functional requirement for generating

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.