> How to do this in c++ ?

How to do this in c++ ?

Posted at: 2014-12-18 
int Ms = 64 * (int) (pow 2.0, m);

char *octets = (char *) calloc (1, Ms);

The 'calloc' function is from plain C, not C++. It allocates memory and zeroes it. Because it's from C, some C++ programmers might avoid it. If so, you could accomplish the same like this:

char *octets = new char[Ms];

for (int i = 0; i < Ms; ++i) octets[i] = 0;

There may also be some spiffy way to do with with the C++ Standard Template Library.

1)

I'm a little confused because your equation: "-Ms = 64*2^m" has odd capitalization and no unknowns

I think what you are getting at is that powers of 2 can be done using the left shift (<<) operator in C++.

64*2^m can be rewritten as 64<
If you want to get the m or the s on the other side watch out for integer round off.

2)

char *buff;

buff = (char*) calloc(m*s,sizeof(char));

Sorry for bad formatting, but i didn't wanted M and S to be multiplied, instead, s is just a little bit below M...

[attaching image of the equation]...

The left side of the equation is much more confusing...



How to write code for these in c++ ?

1. Suppose we have two ints M and S



M = 10

S = 32

How to do this in c++ - Ms = 64?2^m

2. how to allocate Ms bytes for any variable and initialize it to 0 ?

Any questions in mind ?

Feel free to ask.

Thanks,