7 kyu

MOD 256 without the MOD operator

495 of 3,264user5036852

Description:

MOD 256 without the MOD operator

The MOD-operator % (aka mod/modulus/remainder):

Returns the remainder of a division operation.
The sign of the result is the same as the sign of the first operand.
(Different behavior in Python!)

The short unbelievable mad story for this kata:
I wrote a program and needed the remainder of the division by 256. And then it happened: The "5"/"%"-Key did not react. It must be broken! So I needed a way to:

Calculate the remainder of the division by 256 without the %-operator.

Also here some examples:

Input 254  -> Result 254
Input 256  -> Result 0
Input 258  -> Result 2 
Input -258 -> Result -2 (in Python: Result: 254!)

It is always expected the behavior of the MOD-Operator of the language!

The input number will always between -10000 and 10000.

For some languages the %-operator will be blocked. If it is not blocked and you know how to block it, tell me and I will include it.

For all, who say, this would be a duplicate: No, this is no duplicate! There are two katas, in that you have to write a general method for MOD without %. But this kata is only for MOD 256. And so you can create also other specialized solutions. ;-)

Of course you can use the digit "5" in your solution. :-)

I'm very curious for your solutions and the way you solve it. I found several interesting "funny" ways.

Have fun coding it and please don't forget to vote and rank this kata! :-)

I have also created other katas. Take a look if you enjoyed this kata!

Algorithms
Fundamentals
Logic
Mathematics
Restricted
Puzzles

Stats:

CreatedNov 5, 2016
PublishedNov 5, 2016
Warriors Trained5448
Total Skips528
Total Code Submissions9724
Total Times Completed3264
C# Completions202
C Completions627
Java Completions469
JavaScript Completions495
TypeScript Completions94
C++ Completions706
F# Completions60
Ruby Completions82
Python Completions638
CoffeeScript Completions18
Objective-C Completions91
PHP Completions113
Total Stars50
% of votes with a positive feedback rating88% of 674
Total "Very Satisfied" Votes533
Total "Somewhat Satisfied" Votes119
Total "Not Satisfied" Votes22
Total Rank Assessments20
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • user5036852 Avatar
  • jhoffner Avatar
  • ParanoidUser Avatar
  • Dentzil Avatar
  • kazk Avatar
  • narayanswa30663 Avatar
  • Blind4Basics Avatar
  • FArekkusu Avatar
  • hobovsky Avatar
  • saudiGuy Avatar
Ad