Modulo Operator: 4 Practical Uses You Did Not Know

Christian Ezeani

Modulo is a mathematical operation that finds the remainder when an integer is divided by another. It is frequently expressed as mod or symbolized as % , therefore, the expression 5 mod 3 can also be written as 5 % 3 , where 5 is the dividend and 3 is the divisor.

Given two positive numbers, a and n, a modulo n (abbreviated as a mod n) is the remainder of the division of a by n, where a is the dividend and n is the divisor.

For example, the expression 9 % 2 would evaluate to 1 because 9 divided by 2 has a quotient of 4 and a remainder of 1.

The expression 10 % 2 would evaluate to 0 because 10 divided by 2 has a quotient of 5 and a remainder of 0.

Practical Uses of Modulo

Examples below assume that you have the basic knowledge of JavaScript and jQuery library. The use of modulo is not limited to JavaScript but Ill be giving my examples here in JavaScript.

Leap Year

To check if the year, y, is a leap year, you use the expression, y % 4 . The division of a leap year by 4 has 0 remainder, therefore, y % 4 should evaluate to 0 if y is a leap year. The example below shows a function to check if a given year is a leap year.

Card Sharing

A card pack contains 55 cards to be shared among 4 players. Each player must have a maximum of 5 cards on his tray, which means, 20 cards would be given out from the card pack. The example below shows a function that does the card sharing.

Check Multiples of a Number

An even number is known as a number that can be divided by 2 without having any remainder (having 0 remainder). The expression, 4 % 2 evaluates to 0 because 4 is an even number, while the expression 9 % 2 evaluates to 1 because 9 is an odd number. Therefore, 4 is a multiple of 2, but 9 is not a multiple of 2.

The expression, 25 % 5 evaluates to 0 because 25 is a multiple of 5, while the expression 28 % 5 evaluates to 3 because 28 divided 5 has a remainder of 3, therefore, 28 is not a multiple of 5.

Time Calculation

Modulo operator can also be used in time calculations.

Example
Annabel visited her friend at 2:00pm (14:00). She left her friends place after spending 30hrs with her. At what time of the day did she leave her friends place?

Christian Ezeani is a web developer, software engineer, and project manager at Cyberpull Technologies and TeamCYB. My interests range from technology to writing.

Related Articles

Extra Space Storage Option For Your Assistance

When you are thinking of anything, you should first of all know it completely. The more you know about it, the best you can get from it. You will have to work on the areas when you dont know it. more

Things You Need to Know About Background Checks

Background Verification has certainly become very important nowadays considering the kind of environment we live in. There is crime all around. We cant even predict who is right and who is wrong. To get rid of our false interpretation of people, it is mandatory that we do proper verification of t... more

Relationships: Can The Fear Of Abandonment Cause Someone To Be Controlling?

When someone starts to spend time with another person, they might not even think about trying to control what they can or can't do. In fact, this could be the last thing that is on their mind. more

Today's background verification

Confirming various applications and procuring representatives is a totally time-eating strategy which whenever completed physically can bring serious human mistakes. Well, not anymore because of the background verifications in todays world. Background Check-in todays techie age is all mechanical.... more

The Gift Giving of the Bobblehead

There was a gift that one might never expect as they go about to open it. This would be the bobblehead. There are so many good things about the bobblehead that you should know about and this is just the spot to read about them. So, hang on as we give you a quick overview about them. more

Why do You Need Background Verification?

There is wrongdoing all around. We can't foresee who is correct and who isn't right. To dispose of our bogus translation of individuals, it is required that we do an appropriate check of the individual we are contracting, both for office and family. In any case, there are sure things that individ... more

Libra Monthly Horoscope for May 2011

This isn't the best month for your health so take extra precautions to avoid problems. You'll notice that you're more susceptible to the flu and other contagious diseases. You'll also run high fevers if they catch up to you. Start the month off right by taking extra vitamins and preventive over t... more

How to Get More Web Site Traffic Using 3 Free Techniques

Have you been searching for year for a way to drive more web site traffic. I will show you just 3 techniques you can apply in order to get more web site traffic. You don't have to buy any software in order to gain traffic. You don't even need to become an expert marketer and Guess what, these tec... more

Scorpio Monthly Horoscope for May 2011

You'll find the first half of the month varies dramatically depending on how you react to the situations. They'll be situations at work where you feel nobody notices the effort you put forth and others tend to take the credit for your work. more

Diaper bag essentials

Packing your diaper bag can be incredibly stressful, almost as much as realizing that you've forgotten to pack spare diapers! We've compiled a handy list of everything that you'll need in your diaper bag to stop you from forgetting anything vital as well as from over packing. Keep a note of the ... more

Design Your Home As Wished By You With The Availabilities Of Furniture Options

When you plan for the sofafurniture, there are varieties of sofa. You have materials like some will opt for teak wood, some may choose the recron, some may choose for an L shaped sofa. So it goes on. more

Custom Bobbleheads for All

It doesnt matter who you are. Custom bobbleheads might be something you can get. There are all sorts of bodies to put the bobblehead on. So, who would be ever so grateful to have custom bobbleheads? You need to ask yourself another question. Who wouldnt be grateful with custom bobbleheads? more

Personalized Bobbleheads: Great for Weddings

No matter if personalized bobblheads are used as gifts or as part of the ceremony, these personalized bobbleheads are just great to use when weddings are concerned. Here are some of the ways when you can get the personalized bobbleheads that are made to look like the person of the picture which y... more

Why a Custom Bobblehead has a Lot to Offer

If you have been looking for the gift of gifts to give, then a custom bobblehead is just the thing for you. This has been the gift that many others have considered getting and when they have given this gift, they couldnt be happier. When we say custom, we mean custom and there are many things tha... more

7 Habits of Couples in Strong and Healthy Relationships

What makes a relationship healthy and romantic differs from couple to couple. Building a trusting and positive partnership takes effort and time. And sadly, it doesnt simply happen long. For any relationship to become steady and remain strong, you definitely want to put in some work. Below are so... more

Latest Releases

Background Screening Lacks Basic Infrastructure in India

Background Verification has become an important part of recruitment today. With the growing technology and people having trust issues with each other, almost everyone is going through before hiring an employee more

Modulo Operator: 4 Practical Uses You Did Not Know

Modulo is a mathematical operation that finds the remainder when an integer is divided by another. It is frequently expressed as mod or symbolized as %, therefore, the expression 5 mod 3 can also be written as 5 % 3, where 5 is the dividend and 3 is the divisor. more

How Technology is Disrupting Background Verification?

Verifying a number of applications and hiring employees is a very time-consuming process which if done manually can lead to serious human errors. This is an era of technology when tech is revolutionizing each and every sphere in the world, may it be healthcare, finance, banking, or any other. In ... more

5 Reasons Landlords Must Require Tenant Background Checks

Making yourself mindful of an occupants earlier conduct, particularly criminal history, makes you a progressively educated and enabled landowner. All things considered, whats to come is best anticipated by watching the past.Tenant Verificationwould one say one is of the most significant pieces of... more

Introduction of Local Verification in Background Check

The modernization and increase in the techno world have expanded the odds of robberies and cheats on the planet, particularly personality burglaries. Increasingly more personality cheats hold up the traffic of association and their employing procedure ordinary which causes a ton of issues and con... more

Why Background Verification is Important for Companies?

The hiring of new employees in an organization can be a daunting process, especially when an employer cannot predict how the candidate sitting right in front of him is. It is essential to locate the correct up-and-comer with the capabilities and trustworthiness to carry out the responsibility, ye... more

Things You Need to Know About Background Checks

Background Verification has certainly become very important nowadays considering the kind of environment we live in. There is crime all around. We cant even predict who is right and who is wrong. To get rid of our false interpretation of people, it is mandatory that we do proper verification of t... more

Why do You Need Background Verification?

There is wrongdoing all around. We can't foresee who is correct and who isn't right. To dispose of our bogus translation of individuals, it is required that we do an appropriate check of the individual we are contracting, both for office and family. In any case, there are sure things that individ... more

Today's background verification

Confirming various applications and procuring representatives is a totally time-eating strategy which whenever completed physically can bring serious human mistakes. Well, not anymore because of the background verifications in todays world. Background Check-in todays techie age is all mechanical.... more

Tips to Get Your Employment Background Verification Right

Today, almost all companies demand background checks for their employees. But the question is why background checks are needed for the employees? The answer is simple. It gives employers a clear picture of whom they are working with. It has been estimated that around 40% of the resume contains fa... more

Diaper bag essentials

Packing your diaper bag can be incredibly stressful, almost as much as realizing that you've forgotten to pack spare diapers! We've compiled a handy list of everything that you'll need in your diaper bag to stop you from forgetting anything vital as well as from over packing. Keep a note of the ... more

Simple Knowledge That Would Boost Search Engine Ranking in 7 Days

Link building is one of the most important tools for increasing your page rank. In fact, search engines lay more emphasis on the quantity and quality of the links from the other websites linking to yours. A website with poor contents could even rank higher than the ones with contents of the best ... more

Why a Custom Bobblehead has a Lot to Offer

If you have been looking for the gift of gifts to give, then a custom bobblehead is just the thing for you. This has been the gift that many others have considered getting and when they have given this gift, they couldnt be happier. When we say custom, we mean custom and there are many things tha... more

The Gift Giving of the Bobblehead

There was a gift that one might never expect as they go about to open it. This would be the bobblehead. There are so many good things about the bobblehead that you should know about and this is just the spot to read about them. So, hang on as we give you a quick overview about them. more

Personalized Bobbleheads: Great for Weddings

No matter if personalized bobblheads are used as gifts or as part of the ceremony, these personalized bobbleheads are just great to use when weddings are concerned. Here are some of the ways when you can get the personalized bobbleheads that are made to look like the person of the picture which y... more

Recent Articles in Computers and Technology » Programming