Monday, August 17, 2020

Rotating numbers for base 2

using System;
					
public class Program
{
	public static void Main()
	{
		ShowCircle(32);
		
		ShowCircle(512);	
	}
	
	static void ShowCircle(int n) {
		int masker = n - 1;
		for (int i = -(n * 2); i <= n * 2; ++i) {
			Console.WriteLine("{0,6}: {1,6} {2,6} {3,6}", n, i, i & masker, (i % n + n) % n);
		}
	}
}

https://dotnetfiddle.net/DedpF2

No comments:

Post a Comment