Convert Lowercase Character to Uppercase Using Bit Manipulation

package org.wesome.dsalgo;

public class ConvertLowercaseToUppercase {
    public static final char UNDERSCORE = '_';
    public static int A = 65;

    public static char convertLowercaseToUppercase(char ch) {
        System.out.println("character is = " + ch + ", its ascii value is " + Integer.valueOf(ch) + ", ASCII value of underscore is " + Integer.valueOf(UNDERSCORE));
        return (char) (ch & UNDERSCORE);
    }
}
package org.wesome.dsalgo;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.stream.IntStream;

import static org.wesome.dsalgo.ConvertLowercaseToUppercase.A;
import static org.wesome.dsalgo.ConvertLowercaseToUppercase.convertLowercaseToUppercase;

public class ConvertLowercaseToUppercaseTest {
    @Test
    void LowercaseToUppercaseTest1() {
        Assertions.assertEquals('A', convertLowercaseToUppercase('a'));
    }

    @Test
    void LowercaseToUppercaseTest2() {
        Assertions.assertEquals('Z', convertLowercaseToUppercase('z'));
    }

    @Test
    void LowercaseToUppercaseTest3() {
        IntStream.rangeClosed(97, 122).forEach(i -> {
            Assertions.assertEquals(A, convertLowercaseToUppercase((char) i));
            A++;
        });
    }
}
plugins {
    id 'java'
    id "io.freefair.lombok" version "6.4.1"
}

group = 'org.wesome'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_1_8

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
}

test {
    useJUnitPlatform()
}

 

follow us on