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;
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
|
show 12 more comments
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
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 usingstd::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. Returnstd::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
|
show 12 more comments
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
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
c++ biginteger
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 usingstd::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. Returnstd::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
|
show 12 more comments
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 usingstd::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. Returnstd::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
|
show 12 more comments
1 Answer
1
active
oldest
votes
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;
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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;
add a comment |
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;
add a comment |
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;
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;
answered Mar 29 at 14:04
F.WuF.Wu
305 bronze badges
305 bronze badges
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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