cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
How to code circular int?
How to code circular int?
Apr 20, 2017 at 7:12pm UTC
Putarda
(112)
Hello. Whats the best way to code circular int?
So for example I have
int red_color = 255;
and if someone initialize red_color = 256; it will be changed to 1. Because 255 is max value for rgb. Thanks :).
Apr 20, 2017 at 7:16pm UTC
doug4
(1533)
actually, you probably want to change the value to 0 because legal values are 0 - 255.
You want to use the modulo operator:
red_color = red_color % 256;
or
red_color %= 256;
Apr 20, 2017 at 7:43pm UTC
Putarda
(112)
Thanks!
Topic archived. No new replies allowed.