C# implementation of the Binary shift and add algorithm