using System.Globalization;
public static class MyExtensions {
public static T RotateDigitsLeft<T>(this T value, int count) where T : IBinaryInteger<T> {
string text = value.ToString().TrimStart('-');
count = (count % text.Length + text.Length) % text.Length;
char[] digits = new char[text.Length];
for (int i = 0; i < digits.Length; ++i)
digits[i] = text[(i + count) % digits.Length];
string result = new string(digits).TrimStart('0');
return T.Parse(result, CultureInfo.InvariantCulture);
public static T RotateDigitsRight<T>(this T value, int count) where T : IBinaryInteger<T> {
string text = value.ToString().TrimStart('-');
count = text.Length - (count % text.Length + text.Length) % text.Length;
char[] digits = new char[text.Length];
for (int i = 0; i < digits.Length; ++i)
digits[i] = text[(i + count) % digits.Length];
string result = new string(digits);
return T.Parse(result, CultureInfo.InvariantCulture);
public static void Main() {
int resultLeft = value.RotateDigitsLeft(1);
int resultRight = value.RotateDigitsRight(1);
Console.WriteLine($"{value} : {resultLeft} : {resultRight}");