digitalmars.D.learn - How to use Power on D
- Carlos (28/28) Jun 12 2013 So I have this code I'm working on but I get weird results. What
- Infiltrator (5/33) Jun 12 2013 I don't see the problem. You're XORing 2 with 1..16 and getting
- bearophile (4/5) Jun 12 2013 That's one bitwise operator. You want ^^
- Carlos (11/16) Jun 12 2013 I didn't understoof in the first try but Infiltrator told me on
So I have this code I'm working on but I get weird results. What am I doing wrong ? Code : import std.stdio; import std.c.stdlib; void main() { foreach (count; 1 .. 16){ write("Result : ", (2)^(count), " from : ", count, "\n"); } } Prints: Result : 3 from : 1 Result : 0 from : 2 Result : 1 from : 3 Result : 6 from : 4 Result : 7 from : 5 Result : 4 from : 6 Result : 5 from : 7 Result : 10 from : 8 Result : 11 from : 9 Result : 8 from : 10 Result : 9 from : 11 Result : 14 from : 12 Result : 15 from : 13 Result : 12 from : 14 Result : 13 from : 15 Thank you for your time.
Jun 12 2013
On Thursday, 13 June 2013 at 00:24:18 UTC, Carlos wrote:So I have this code I'm working on but I get weird results. What am I doing wrong ? Code : import std.stdio; import std.c.stdlib; void main() { foreach (count; 1 .. 16){ write("Result : ", (2)^(count), " from : ", count, "\n"); } } Prints: Result : 3 from : 1 Result : 0 from : 2 Result : 1 from : 3 Result : 6 from : 4 Result : 7 from : 5 Result : 4 from : 6 Result : 5 from : 7 Result : 10 from : 8 Result : 11 from : 9 Result : 8 from : 10 Result : 9 from : 11 Result : 14 from : 12 Result : 15 from : 13 Result : 12 from : 14 Result : 13 from : 15 Thank you for your time.I don't see the problem. You're XORing 2 with 1..16 and getting the correct results. Unless you actually want std.math.pow
Jun 12 2013
Carlos:Thank you for your time.That's one bitwise operator. You want ^^ Bye, bearophile
Jun 12 2013
On Thursday, 13 June 2013 at 00:27:33 UTC, bearophile wrote:Carlos:I didn't understoof in the first try but Infiltrator told me on the #d irc chat and here is the new code. import std.stdio; import std.c.stdlib; void main() { foreach (count; 1 .. 16){ write("Result : ", (2)^^(count), " from : ", count, "\n"); } }Thank you for your time.That's one bitwise operator. You want ^^ Bye, bearophile
Jun 12 2013