Problem in converting a biginteger binary string 128 bit to an array int [4]How to concatenate a std::string and an int?How to convert std::string to lower case?How to convert a std::string to const char* or char*?How to convert int to QString?Converting from Integer, to BigIntegerConvert char to int in C and C++Easiest way to convert int to string in C++How can I convert a std::string to int?Converting BigInteger to binary stringBig Int implementation, how to handle leading zeros?

If hash functions append the length, why does length extension attack work?

I am a dual citizen of United States and Mexico, can I use my Mexican license in california when visiting?

My current job follows "worst practices". How can I talk about my experience in an interview without giving off red flags?

What is the metal bit in the front of this propeller spinner?

Is it ethical to tell my teaching assistant that I like him?

Has Iron Man made any suit for underwater combat?

As a DM of a 4-player group, would it be appropriate for me to run a private 1-on-1 session so that one PC can act secretly?

Is it better to deliver many low-value stories or few high-value stories?

Why did modems have speakers?

Can I make Ubuntu 18.04 switch between multiple windows of the program by just clicking the icon?

Storyboarding Approaches for the Non-Artistic

Calculating Fibonacci sequence in several different ways

Can I use Sitecore's Configuration patching mechanics for my Identity Server configuration?

Why was Quirrell said to be in the Black Forest if Voldemort was actually in Albania?

What is the best word describing the nature of expiring in a short amount of time, connoting "losing public attention"?

Do I care if the housing market has gone up or down, if I'm moving from one house to another?

Can the caster of Time Stop still use their bonus action or reaction?

Found more old paper shares from broken up companies

How can I disable a reserved profile?

Count the identical pairs in two lists

MITM on HTTPS traffic in Kazakhstan 2019

Caption in landscape table, need help?

Would using carbon dioxide as fuel work to reduce the greenhouse effect?

Strange LED behavior



Problem in converting a biginteger binary string 128 bit to an array int [4]


How to concatenate a std::string and an int?How to convert std::string to lower case?How to convert a std::string to const char* or char*?How to convert int to QString?Converting from Integer, to BigIntegerConvert char to int in C and C++Easiest way to convert int to string in C++How can I convert a std::string to int?Converting BigInteger to binary stringBig Int implementation, how to handle leading zeros?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















My method is setting bit in each elements of the int array. Althought the program works with the case where the string str="11111...111" (all the bit is 1)
However, in case as the string str="100...000" (63 zero numbers)(the first bit is 1 and the rest are 0) the problem occurs, my int array is 0,0,0,1 it has to be 0,0,1,0
Please give me a solution with my code, if your idea is better, tell me so i can fix the problem soon.



int arr[4]=0;
void convert(string str)


int length = str.length();
for (int i = length - 1; i >= 0; i--)

if (str[i] == '1')
arr[pos];





If the string has 1000...00 (32 0 numbers ), the int array has to be 0,0,1,0
If the string has 1000...00 (63 0 numbers), the int array has to be 0,1,0,0










share|improve this question



















  • 2





    Please read the help pages, especially "What topics can I ask about here?" and "What types of questions should I avoid asking?". Also take the tour and read about how to ask good questions and this question checklist. Lastly learn how to create a minimal reproducible example.

    – Some programmer dude
    Mar 26 at 13:42






  • 2





    what is "the problem" ? btw using std::bitset makes bit fiddling much simpler

    – formerlyknownas_463035818
    Mar 26 at 13:42






  • 3





    half of this sentence seems to be missing: "However, in case as the string str="100...000" (...)" .. what happens in that case?

    – formerlyknownas_463035818
    Mar 26 at 13:43






  • 1





    That pointer you’re returning becomes invalid as soon as the function returns. Return std::array or pass the array into the function.

    – molbdnilo
    Mar 26 at 14:04






  • 4





    @F.Wu Attempts to fix bugs by adding code are very seldom successful. Sit down and work out the logic (preferrably away from the keyboard) instead of trying to handle special cases.

    – molbdnilo
    Mar 26 at 14:44


















0















My method is setting bit in each elements of the int array. Althought the program works with the case where the string str="11111...111" (all the bit is 1)
However, in case as the string str="100...000" (63 zero numbers)(the first bit is 1 and the rest are 0) the problem occurs, my int array is 0,0,0,1 it has to be 0,0,1,0
Please give me a solution with my code, if your idea is better, tell me so i can fix the problem soon.



int arr[4]=0;
void convert(string str)


int length = str.length();
for (int i = length - 1; i >= 0; i--)

if (str[i] == '1')
arr[pos];





If the string has 1000...00 (32 0 numbers ), the int array has to be 0,0,1,0
If the string has 1000...00 (63 0 numbers), the int array has to be 0,1,0,0










share|improve this question



















  • 2





    Please read the help pages, especially "What topics can I ask about here?" and "What types of questions should I avoid asking?". Also take the tour and read about how to ask good questions and this question checklist. Lastly learn how to create a minimal reproducible example.

    – Some programmer dude
    Mar 26 at 13:42






  • 2





    what is "the problem" ? btw using std::bitset makes bit fiddling much simpler

    – formerlyknownas_463035818
    Mar 26 at 13:42






  • 3





    half of this sentence seems to be missing: "However, in case as the string str="100...000" (...)" .. what happens in that case?

    – formerlyknownas_463035818
    Mar 26 at 13:43






  • 1





    That pointer you’re returning becomes invalid as soon as the function returns. Return std::array or pass the array into the function.

    – molbdnilo
    Mar 26 at 14:04






  • 4





    @F.Wu Attempts to fix bugs by adding code are very seldom successful. Sit down and work out the logic (preferrably away from the keyboard) instead of trying to handle special cases.

    – molbdnilo
    Mar 26 at 14:44














0












0








0








My method is setting bit in each elements of the int array. Althought the program works with the case where the string str="11111...111" (all the bit is 1)
However, in case as the string str="100...000" (63 zero numbers)(the first bit is 1 and the rest are 0) the problem occurs, my int array is 0,0,0,1 it has to be 0,0,1,0
Please give me a solution with my code, if your idea is better, tell me so i can fix the problem soon.



int arr[4]=0;
void convert(string str)


int length = str.length();
for (int i = length - 1; i >= 0; i--)

if (str[i] == '1')
arr[pos];





If the string has 1000...00 (32 0 numbers ), the int array has to be 0,0,1,0
If the string has 1000...00 (63 0 numbers), the int array has to be 0,1,0,0










share|improve this question
















My method is setting bit in each elements of the int array. Althought the program works with the case where the string str="11111...111" (all the bit is 1)
However, in case as the string str="100...000" (63 zero numbers)(the first bit is 1 and the rest are 0) the problem occurs, my int array is 0,0,0,1 it has to be 0,0,1,0
Please give me a solution with my code, if your idea is better, tell me so i can fix the problem soon.



int arr[4]=0;
void convert(string str)


int length = str.length();
for (int i = length - 1; i >= 0; i--)

if (str[i] == '1')
arr[pos];





If the string has 1000...00 (32 0 numbers ), the int array has to be 0,0,1,0
If the string has 1000...00 (63 0 numbers), the int array has to be 0,1,0,0







c++ biginteger






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 14:37







F.Wu

















asked Mar 26 at 13:36









F.WuF.Wu

305 bronze badges




305 bronze badges







  • 2





    Please read the help pages, especially "What topics can I ask about here?" and "What types of questions should I avoid asking?". Also take the tour and read about how to ask good questions and this question checklist. Lastly learn how to create a minimal reproducible example.

    – Some programmer dude
    Mar 26 at 13:42






  • 2





    what is "the problem" ? btw using std::bitset makes bit fiddling much simpler

    – formerlyknownas_463035818
    Mar 26 at 13:42






  • 3





    half of this sentence seems to be missing: "However, in case as the string str="100...000" (...)" .. what happens in that case?

    – formerlyknownas_463035818
    Mar 26 at 13:43






  • 1





    That pointer you’re returning becomes invalid as soon as the function returns. Return std::array or pass the array into the function.

    – molbdnilo
    Mar 26 at 14:04






  • 4





    @F.Wu Attempts to fix bugs by adding code are very seldom successful. Sit down and work out the logic (preferrably away from the keyboard) instead of trying to handle special cases.

    – molbdnilo
    Mar 26 at 14:44













  • 2





    Please read the help pages, especially "What topics can I ask about here?" and "What types of questions should I avoid asking?". Also take the tour and read about how to ask good questions and this question checklist. Lastly learn how to create a minimal reproducible example.

    – Some programmer dude
    Mar 26 at 13:42






  • 2





    what is "the problem" ? btw using std::bitset makes bit fiddling much simpler

    – formerlyknownas_463035818
    Mar 26 at 13:42






  • 3





    half of this sentence seems to be missing: "However, in case as the string str="100...000" (...)" .. what happens in that case?

    – formerlyknownas_463035818
    Mar 26 at 13:43






  • 1





    That pointer you’re returning becomes invalid as soon as the function returns. Return std::array or pass the array into the function.

    – molbdnilo
    Mar 26 at 14:04






  • 4





    @F.Wu Attempts to fix bugs by adding code are very seldom successful. Sit down and work out the logic (preferrably away from the keyboard) instead of trying to handle special cases.

    – molbdnilo
    Mar 26 at 14:44








2




2





Please read the help pages, especially "What topics can I ask about here?" and "What types of questions should I avoid asking?". Also take the tour and read about how to ask good questions and this question checklist. Lastly learn how to create a minimal reproducible example.

– Some programmer dude
Mar 26 at 13:42





Please read the help pages, especially "What topics can I ask about here?" and "What types of questions should I avoid asking?". Also take the tour and read about how to ask good questions and this question checklist. Lastly learn how to create a minimal reproducible example.

– Some programmer dude
Mar 26 at 13:42




2




2





what is "the problem" ? btw using std::bitset makes bit fiddling much simpler

– formerlyknownas_463035818
Mar 26 at 13:42





what is "the problem" ? btw using std::bitset makes bit fiddling much simpler

– formerlyknownas_463035818
Mar 26 at 13:42




3




3





half of this sentence seems to be missing: "However, in case as the string str="100...000" (...)" .. what happens in that case?

– formerlyknownas_463035818
Mar 26 at 13:43





half of this sentence seems to be missing: "However, in case as the string str="100...000" (...)" .. what happens in that case?

– formerlyknownas_463035818
Mar 26 at 13:43




1




1





That pointer you’re returning becomes invalid as soon as the function returns. Return std::array or pass the array into the function.

– molbdnilo
Mar 26 at 14:04





That pointer you’re returning becomes invalid as soon as the function returns. Return std::array or pass the array into the function.

– molbdnilo
Mar 26 at 14:04




4




4





@F.Wu Attempts to fix bugs by adding code are very seldom successful. Sit down and work out the logic (preferrably away from the keyboard) instead of trying to handle special cases.

– molbdnilo
Mar 26 at 14:44






@F.Wu Attempts to fix bugs by adding code are very seldom successful. Sit down and work out the logic (preferrably away from the keyboard) instead of trying to handle special cases.

– molbdnilo
Mar 26 at 14:44













1 Answer
1






active

oldest

votes


















0














So i have found a solution for my own problem. Please help me test my code then let me know if any test cases make errors. Thank you.



class QInt

private:
int Data[4];
public:
QInt()

for (int i = 0; i < 4; i++)

Data[i] = 0;




QInt QInt::StrBinToQInt(string str)

QInt temp=QInt();
str = creString128(str);
cout << str.length() << endl;
cout << str << endl;
for (int i = 127; i >= 0; i--)

int pos;
if (str[i] == '1')

pos = i / 32;
int k = (127-i) % 32;
if (i % 32 == 0)

pos--;
k = 0;

if (str[0] == '1')

pos = 0;
k = 30;

temp.Data[pos] = (1 << k)

return temp;


;

string creString(int n)

string temp;
for (int i = 0; i < n; i++)

temp += '0';

return temp;


string creString128(string bin)

string corrBin = creString(128 - bin.length());
corrBin += bin;
return corrBin;






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55358523%2fproblem-in-converting-a-biginteger-binary-string-128-bit-to-an-array-int-4%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    So i have found a solution for my own problem. Please help me test my code then let me know if any test cases make errors. Thank you.



    class QInt

    private:
    int Data[4];
    public:
    QInt()

    for (int i = 0; i < 4; i++)

    Data[i] = 0;




    QInt QInt::StrBinToQInt(string str)

    QInt temp=QInt();
    str = creString128(str);
    cout << str.length() << endl;
    cout << str << endl;
    for (int i = 127; i >= 0; i--)

    int pos;
    if (str[i] == '1')

    pos = i / 32;
    int k = (127-i) % 32;
    if (i % 32 == 0)

    pos--;
    k = 0;

    if (str[0] == '1')

    pos = 0;
    k = 30;

    temp.Data[pos] = (1 << k)

    return temp;


    ;

    string creString(int n)

    string temp;
    for (int i = 0; i < n; i++)

    temp += '0';

    return temp;


    string creString128(string bin)

    string corrBin = creString(128 - bin.length());
    corrBin += bin;
    return corrBin;






    share|improve this answer



























      0














      So i have found a solution for my own problem. Please help me test my code then let me know if any test cases make errors. Thank you.



      class QInt

      private:
      int Data[4];
      public:
      QInt()

      for (int i = 0; i < 4; i++)

      Data[i] = 0;




      QInt QInt::StrBinToQInt(string str)

      QInt temp=QInt();
      str = creString128(str);
      cout << str.length() << endl;
      cout << str << endl;
      for (int i = 127; i >= 0; i--)

      int pos;
      if (str[i] == '1')

      pos = i / 32;
      int k = (127-i) % 32;
      if (i % 32 == 0)

      pos--;
      k = 0;

      if (str[0] == '1')

      pos = 0;
      k = 30;

      temp.Data[pos] = (1 << k)

      return temp;


      ;

      string creString(int n)

      string temp;
      for (int i = 0; i < n; i++)

      temp += '0';

      return temp;


      string creString128(string bin)

      string corrBin = creString(128 - bin.length());
      corrBin += bin;
      return corrBin;






      share|improve this answer

























        0












        0








        0







        So i have found a solution for my own problem. Please help me test my code then let me know if any test cases make errors. Thank you.



        class QInt

        private:
        int Data[4];
        public:
        QInt()

        for (int i = 0; i < 4; i++)

        Data[i] = 0;




        QInt QInt::StrBinToQInt(string str)

        QInt temp=QInt();
        str = creString128(str);
        cout << str.length() << endl;
        cout << str << endl;
        for (int i = 127; i >= 0; i--)

        int pos;
        if (str[i] == '1')

        pos = i / 32;
        int k = (127-i) % 32;
        if (i % 32 == 0)

        pos--;
        k = 0;

        if (str[0] == '1')

        pos = 0;
        k = 30;

        temp.Data[pos] = (1 << k)

        return temp;


        ;

        string creString(int n)

        string temp;
        for (int i = 0; i < n; i++)

        temp += '0';

        return temp;


        string creString128(string bin)

        string corrBin = creString(128 - bin.length());
        corrBin += bin;
        return corrBin;






        share|improve this answer













        So i have found a solution for my own problem. Please help me test my code then let me know if any test cases make errors. Thank you.



        class QInt

        private:
        int Data[4];
        public:
        QInt()

        for (int i = 0; i < 4; i++)

        Data[i] = 0;




        QInt QInt::StrBinToQInt(string str)

        QInt temp=QInt();
        str = creString128(str);
        cout << str.length() << endl;
        cout << str << endl;
        for (int i = 127; i >= 0; i--)

        int pos;
        if (str[i] == '1')

        pos = i / 32;
        int k = (127-i) % 32;
        if (i % 32 == 0)

        pos--;
        k = 0;

        if (str[0] == '1')

        pos = 0;
        k = 30;

        temp.Data[pos] = (1 << k)

        return temp;


        ;

        string creString(int n)

        string temp;
        for (int i = 0; i < n; i++)

        temp += '0';

        return temp;


        string creString128(string bin)

        string corrBin = creString(128 - bin.length());
        corrBin += bin;
        return corrBin;







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 29 at 14:04









        F.WuF.Wu

        305 bronze badges




        305 bronze badges


















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55358523%2fproblem-in-converting-a-biginteger-binary-string-128-bit-to-an-array-int-4%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현