How do u find the leap year withput using division and modulo operator in your program??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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

26th Sep 2017, 12:11 PM
shwetha lokesh
shwetha lokesh - avatar
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
26th Sep 2017, 12:41 PM
Apoorva Shenoy Nayak
Apoorva Shenoy Nayak - avatar
26th Sep 2017, 1:38 PM
Calviղ
Calviղ - avatar