Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
How do u find the leap year withput using division and modulo operator in your program???
2 Respostas
+ 10
Here are some ways of identifying leap years without using a modulo function.
Firstly, letās assume (or test) that the year is in the range 1901 - 2099.
(a) A leap year expressed as a binary number will have 00 as the last two digits. So:
itās a leap year if year & (not 4) == 0
(b) If you have a function available to truncate a real number to an integer then this works:
x = trunc(year / 4)
itās a leap year if x * 4 == year
(c) If you have shift (not circular shift) operators, which Iām sure Verilog has then:
x = year >> 2
itās a leap year if (x << 2) == year
If the assumption about the range being 1901 - 2099 is false then youāll need some extra logic to eliminate 1900, 1800, 1700 and 2100, 2200, 2300 and so on.
Source: Quora