0

My question is whether I can only switch bits B6, B5 to create a toUpper() function or if I would need to split the bits into separate parts

ASCII Bit representations An example shift of this type would be:

1000001 to 1100001 (A to a)

rcpayung
  • 23
  • 4

2 Answers2

1

You can shift just one bit using masking but there is a much simpler way.

if ('a' <= ch && ch <= 'z')
    ch -= 'a' - 'A'; // subtract 32
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0
public static final int BIT5 = 0x20;

int A = 0b1000001;
int a = setBits(A, BIT5);

public static int setBits(int val, int bits) {
    return val | bits;
}

public static int clearBits(int val, int bits) {
    return val & ~bits;
}
Oleg Cherednik
  • 17,377
  • 4
  • 21
  • 35