0

# How do u find the leap year withput using division and modulo operator in your program???

2 Answers

+ 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