Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a problem to read a large int ( 1 to 10^100 ) into vector the problem is I cannot read it as numeric data-type and split it into the vector so I want a solution to read the number separately into the vector
Example:
45686469
vec[0] = 4
vec[1] = 5
...
vec[7] = 9
Here's one possible way to do it:
std::string yourinput;
cin>>yourinput; //capture your large number as a string
std::vector<char> vch;
for(size_t st=0;st<yourinput.length();++st)
{
vch.push_back(yourinput[st]); //move each character into the vector
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 months ago.
Improve this question
For example I want to do:
I have 1 it is 00000001 in binary.
and when I shift like 1<<3 I'll take 8 it is 00001000.
So, I need that I take 00001111 after 1<<3.
I wish you understand if something wrong add unclear ask about it please.
I want to do shorter this part:
for(int i=1;h>0;h--,i*=2) hr+=i;
As I understand, you want
std::uint32_t my_shift(std::uint32_t n, std::uint32_t lshift)
{
return (n << lshift) | ((1 << lshift) - 1);
// original shifted | 0b0001111 (lshift 1)
}
You can directly iterate hr:
for(int hr=1; h>0; h--, hr=2*hr+1)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
How can i convert boost cpp_int (>1000 bits) to it's binary representation in string (e.g. "1011....11001") ?
I have tried convert it by std::bitset, but it does not work on higher numbers
Edit - solution:
This contains a solution for this question:
Instead of int -> cpp_int
std::string toBinary(boost::multiprecision::cpp_int n)
{
std::string r;
while(n != 0)
{
r = (n % 2 == 0 ? "0":"1") + r;
n /= 2;
}
return r;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How can i print all complete square numbers available in the array
this is my array:
int main()
{
int array[6];
cout<<"Enter 6 #'s: "<<endl;
for(int i=0; i<6; i++) {
cin>>array[i];
}
Here's the algorithm:
For each slot in the array do:
if value in the slot is complete square number, print it.
The difficult part is determining a perfect square.
Hint: use sqrt (square root) function.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Increment a alpha numerical string "abcd1234" upto "abcd2000"
output:
abcd1234
abcd1235
.
.
.
abcd2000
Simply:
for (int a = 1234; a <= 2000; ++a)
{
std::cout << "abcd" << a;
}
In C,
for (int i=1234; i<= 2000;i++)
printf("abcd%d\n",i);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a signal x(t). I must shift it a/2 and -a/2 and then take the sum of these two shifted signals. How can I write shift of x(t) in time in C++?
For time series data a shift in time is just an offset of n samples, so to sum data which is shifted by +/-a/2 samples:
for (i = a/2; i < N - a/2; ++i)
{
y[i] = x[i - a/2] + x[i + a/2];
}