sphil79 February 2016
### How to return 1 if the ASCII is uppercase

I have to return 1 if x is in between 0x41 and 0x5a (ascii for 'A' to 'Z'). Only bitwise operators are allowed (`~`

, `&`

, `^`

, `|`

, `<<`

, `>>`

), plus `!`

and `+`

. Library functions like `isupper`

are not.

I'd appreciate any tips or help because I understand which ranges work, but I don't know how to manipulate it to return 1 with the given operators.

**Hint 1** - Subtraction can be accomplished by adding negative numbers.

**Hint 2** - Negation can be done with bitwise operators: `-n == ~n+1`

.

**Hint 3** - Right shifting a non-negative number by *n* is equivalent to dividing by 2^{n}: `n>>1 == n/2`

, `n>>2 == n/4`

, etc.

Asked in February 2016

Viewed 2,373 times

Voted 8

Answered 1 times

Viewed 2,373 times

Voted 8

Answered 1 times