hello, everyone.
I am stuck in solidity 0.8.4
In the picture, How can I replace the "d & -d" for no-error?
Jun 14, 2022, 12:39 PM
-1*d
Jun 14, 2022, 12:53 PM
thank for your reply, but it still doesn't work
Jun 14, 2022, 12:58 PM
change the data type too. Uint = unsigned int (meaning only +ve number)
Chnge it to int which includes both +ve and -ve
Chnge it to int which includes both +ve and -ve
something like this.
Jun 14, 2022, 1:21 PM
I found solution
uint256 pow2 = d & ~d;
how about do you think?
uint256 pow2 = d & ~d;
how about do you think?
Jun 14, 2022, 1:40 PM
0
Jun 14, 2022, 1:41 PM
?
Jun 14, 2022, 1:53 PM
It's always gonna be zero, regardless of d
Jun 14, 2022, 1:59 PM
then what's the solution?
Jun 14, 2022, 2:01 PM
Casting
Jun 14, 2022, 2:02 PM
the standard library is "pow2 = d & (-d)"
Isn't it always zero?
Isn't it always zero?
Jun 14, 2022, 2:02 PM
Actually defining what you're doing
Jun 14, 2022, 2:02 PM
I am afraid of making an error
Jun 14, 2022, 2:03 PM
-d is different from ~d
-d uses the two's complement. ~d the one's complement
int_8 d = 39;
int pow2 = d & (int_8(-1)*d);
int pow2 = d & (int_8(-1)*d);
Jun 14, 2022, 2:05 PM
You are right.
I solved this problem like below
How about do you think?
I solved this problem like below
How about do you think?
Jun 16, 2022, 6:26 AM
Looks right. I don't get why you didn't use my code bc it'd save a small amount of gas and be less code but your code looks right too
Jun 16, 2022, 6:32 AM
your code is error
Jun 16, 2022, 6:36 AM
I thought d was a unit_8. It was on the screenshot you showed me
Then just change that uint_8 in my code to uint_256
Jun 16, 2022, 6:42 AM
d is uint256
Jun 16, 2022, 6:42 AM
Oh wait sry i read it wrong. It never was a unit_8
Jun 16, 2022, 6:42 AM
anyway, thanks for you reply
And this is other problem.
Do you know why ganache hangs in open workspace?
And this is other problem.
Do you know why ganache hangs in open workspace?
Jun 16, 2022, 6:44 AM
Idk what open workspace is
Jun 16, 2022, 6:44 AM
Ganache hangs when opening truffle workspace
https://t.me/dev_solidity/182868
Jun 16, 2022, 6:46 AM
Oh I've never used that. I only use the cli version
Jun 16, 2022, 6:46 AM
do you mean "truffle develop" console?
Jun 16, 2022, 6:47 AM
It's called ganache-cli but has been renamed to just ganache half a year ago
Jun 16, 2022, 6:49 AM
could you explain about usage of ganache-cli?
Jun 16, 2022, 6:49 AM
You enter ganache-cli into a terminal and it starts a dev chain for you
Jun 16, 2022, 6:50 AM
should I install it of course?
what do I have to do?
it will improve vscode terminal speed
Jun 16, 2022, 7:25 AM
Use ganache npm package globally..
npm i -g ganache
Jun 16, 2022, 7:58 AM
then you will find these
Jun 16, 2022, 8:00 AM