public void IsOdd_ShouldReturnValidResult_ForUInt32() { // Arrange. UInt32 twoHundredFiftySix = 256; UInt32 eleven = 11; UInt32 zero = 0; UInt32 one = 1; UInt32 two = 2; UInt32 three = 3; UInt32 four = 4; // Act. var resultOne = twoHundredFiftySix.IsOdd(); var resultTwo = eleven.IsOdd(); var resultThree = zero.IsOdd(); var resultFour = one.IsOdd(); var resultFive = two.IsOdd(); var resultSix = three.IsOdd(); var resultSeven = four.IsOdd(); // Assert. resultOne.Should().BeFalse(); resultTwo.Should().BeTrue(); resultThree.Should().BeFalse(); resultFour.Should().BeTrue(); resultFive.Should().BeFalse(); resultSix.Should().BeTrue(); resultSeven.Should().BeFalse(); }
public static string ConvertToBinary(UInt32 d) { if (d == 0) { return("0"); } string bin = string.Empty; while (d > 0) { if (d.IsOdd()) { bin = "1" + bin; d = d - 1; } else { bin = "0" + bin; } d = d / 2; } return(bin); }
public static void RequireArgumentIsEven(UInt32 valueArgument, [NotNull] String nameArgument) { nameArgument.RequireArgumentHasNonWhiteSpaceValue("nameArgument"); if (valueArgument.IsOdd()) { throw new ArgumentOutOfRangeException(nameArgument, valueArgument, String.Format(CultureInfo.InvariantCulture, "{0}.", Resources.ValueMustBeEven)); } }