.
.
.
Hope this helps.
It did, thanks for your help.
.
.
.
Hope this helps.
It did, thanks for your help.
...
you can reduce it to just 4 AND operations by using 4 bit masks.
...
That is correct I can get the 4 times 2 bit's by using bitmasks,
But I will still need to shift/div to get the integervalue.
Maybe I wasn't clear on my problem.
say the following 1byte pattern 0x9c
in binary: 1001 1100
then I would like to have the 4 times 2 bit integer represententation in this case
2-1-3-0
But thanks for your reply
I don't really understand what you want.
Strings(c++) and chararrays(c) can be arbitrarily long.
So do you want a datastructure to hold an infinite amount of different strings?
You need to elaborate on your problem
Hi again,
thanks for the reply and the added info.
But I still fail to see why your code should be more efficient.
For each char i do 4 shift operations and 4 bitwise AND's, thats 8 bitwise operations.
For each char you do 4 shifts in the middle loop, futhermore you do 2 shifts for each passing of the inner loop. And you write youself, a multiplication of 2 means a shift by 1. So futhermore you do another shift in line19. That sums your program to 16 shift operations.
And concerning the bitwise AND's. You do 4 shifts in the middle loop, and 2 more in the inner most loop, that sums to 12 AND. And a total of 28 bitwise operations.
That is, if I'm not mistaken.
What was wrong with gsl?
What do you want to optimize, is it a maximization/minimization you want. Or is it a linear programming problem.
I've use it for maximization problems,
and found it strange that I needed to supply a,
gradient function, and also use special gsl vectors.
But other than that it worked nicely.
Hi thanks for the replys.
@duoas
can you elaborate on why your code is more efficient?
and can you tell me why you choose to use %ld at line 22
If you are new to the parallel way of doing things,
I wouldn't start with MPI.
You should start with simple threading.
And pthreads are installed by default,
and has quite good documentation.
good luck
Hi,
given a char(8bit's), I want to get the value of every 2bits,
so that a char will contain 4 values.
This is easily done with a shift left command (<<2).
As far as I understand,
char arrays are simply the different chars in consecutive order in the memory.
so essentially, I should be able to just shift2, through the entire array.
This is a short snippet that does want I want but not in the correct way.
int main(int argc, char *arg[]){
unsigned char *chr = new unsigned char[8];
for(int i=0;i<8;i++)
chr[i] = 0x80 ;
int i=0;
unsigned char tmp;
while(i<8){
printf("11xx-xxxx bits of chr[%d]=%x\n",i,tmp&0xc0); //extract 1100 0000
tmp = tmp<<2;
printf("xx11-xxxx bits of chr[%d]=%x\n",i,tmp&0xc0); //extract 0011 0000
tmp = tmp<<2;
printf("xxxx-11xx bits of chr[%d]=%x\n",i,tmp&0xc0); //extract 0011 0000
tmp = tmp<<2;
printf("xx11-xx11 bits of chr[%d]=%x\n",i,tmp&0xc0); //extract 0011 0000
i++;
}
Basicly i would like to avoid doing 4 times 2 shift for each char.
and just do shift2 all the way through the array.
like
while(chararray not empty){
print first 2 bits
shift chararray 2 bits
}
thanks in advance
Hi again,
I realized that objects is passed by value, so I just need to and and & to the function declaration.
Hi I'm doing a statistical mcmc model where I need some random numbers.
I decided to use the ranrot-w generator.
The random number only works when I call the randomnumber method directly,
and not when i give the random number as an parameter to another function.
that is
rg.Random() !=random(rg)
where random simply calls the Random method in the class.
Below is a cut-down code snippet, that illustrates the problem,
it compiles and works under the g++ compiler.
and also the output from the program, it clearly show the the randomizer returns the same value, when called indirectly.
thanks in advance
dddddddddddddddddddddddddddddddd: 0.571800
dddddddddddddddddddddddddddddddd: 0.493439
dddddddddddddddddddddddddddddddd: 0.518434
dddddddddddddddddddddddddddddddd: 0.322902
dddddddddddddddddddddddddddddddd: 0.996980
dddddddddddddddddddddddddddddddd: 0.188140
dddddddddddddddddddddddddddddddd: 0.188140
dddddddddddddddddddddddddddddddd: 0.188140
dddddddddddddddddddddddddddddddd: 0.188140
dddddddddddddddddddddddddddddddd: 0.188140
#include <iostream>
#include <math.h>
#include <stdio.h>
// Define 32 bit signed and unsigned integers.
// Change these definitions, if necessary, on 64 bit computers
typedef signed long int32;
typedef unsigned long uint32;
class TRanrotWGenerator { // encapsulate random number generator
enum constants { // define parameters
KK = 17, JJ = 10, R1 = 19, R2 = 27};
public:
double random_normal(double esp,double var);
void RandomInit(uint32 seed); // initialization
int IRandom(int min, int max); // get integer random number in desired interval
long double Random(); // get floating point random number
uint32 BRandom(); // output random bits
TRanrotWGenerator(uint32 seed); // constructor
protected:
int p1, p2; // indexes into buffer
union { // used for conversion to float
long …