I'm using a programming language (more a scripting language) that does not support any bitwise operators like AND, OR, XOR, NOT (and shift as well).
Common arithmetic and logical operations like + - * / % > >= < <= == !=, logical AND, OR, NOT and control flow (while, for, if,...) are supported however. It is like a "subset of C", but without these binary operators. My question does not target that particular language anyway.
I was wondering if there is any (mathematical ?) way to set and check a bit at a specific position in a programming language that does not support bitwise operations :
a = 0; //00000000b a = togglebit(a, 5); //00100000b a = togglebit(a, 2); //00100100b a = 0xFE; //11111110b bool result = checkbit(a, 4); //true
For example, there is a way to perform a left or right binary shift using integer multiplication or division :
a = a * 2; //similar to left shift : a = a << 1; a = a / 2; //similar to right shift : a = a >> 1;
I'm looking for something similar but for setting or checking a flag.