I need a function with a header like this:
bool is_prefix(int a, int b, int* c) {
If a is read as a binary numeric string, the prefix is b, then set * c as the rest of b (that is, "that b has more than") and return true. Otherwise, return false. Suppose binary strings always begin with "1".
Of course - this is easy to do by comparing in half (left shift b to b == a). But is there a solution that is more efficient without repeating bits?
Example: a = 100 (4), b = 1001 (9). Now set *c to 1.
source share