Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ZigZag
- {
- class Program
- {
- static Random rnd = new Random();
- static void Main(string[] args)
- {
- Parallel.For(int.MinValue, (long)int.MaxValue +1, i =>
- {
- int x = (int)i;
- uint zig = (uint)((x << 1) ^ (x >> 31));
- var zag = ((int)(zig >> 1)) ^ ((int)(-(zig & 1)));
- if (x != zag)
- {
- Console.WriteLine(x + " : " + zig + " : " + zag);
- Console.WriteLine(ToBits(x));
- Console.WriteLine(ToBits(zig));
- Console.WriteLine(ToBits(zag));
- Console.WriteLine("ERROR");
- }
- });
- Console.WriteLine("Finished!");
- Console.ReadLine();
- }
- public static string ToBits(int i)
- {
- var bits = Convert.ToString(i, 2).PadLeft(32, '0');
- return bits.Substring(0, 8) + " " + bits.Substring(8, 8) + " " + bits.Substring(16, 8) + " " + bits.Substring(24, 8);
- }
- public static string ToBits(uint i)
- {
- var bits = Convert.ToString(i, 2).PadLeft(32, '0');
- return bits.Substring(0, 8) + " " + bits.Substring(8, 8) + " " + bits.Substring(16, 8) + " " + bits.Substring(24, 8);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment