Member-only story

#JavaSolved : Bitwise One

#ActionPills | Shawal 🇵🇸
2 min readSep 24, 2022

--

Have the function BitwiseOne(strArr) take the array of strings stored in strArr, which will only contain two strings of equal length that represent binary numbers, and return a final binary string that performed the bitwise OR operation on both strings. A bitwise OR operation places a 0 in the new string where there are zeroes in both binary strings, otherwise it places a 1 in that spot. For example: if strArr is [“1001”, “0100”] then your program should return the string “1101”.

Examples

Input: new String[] {“100”, “000”}

Output: 100

Input: new String[] {“00011”, “01010”}

Output: 01011

import java.util.*;

import java.io.*;

class Main {

static String BitwiseOne(String[] strArr) {

String res=””;

int max_size = Integer.MIN_VALUE;

for (int i=0; i<strArr.length; i++){

max_size = Math.max(max_size, (int)strArr[i].length());

strArr[i] = reverse(strArr[i]);

}

for (int i=0; i<strArr.length;i++){

String m=””;

for (int j=0; j<max_size-strArr[i].length(); j++)

--

--

#ActionPills | Shawal 🇵🇸
#ActionPills | Shawal 🇵🇸

Written by #ActionPills | Shawal 🇵🇸

Sharing weekly #ActionPills for both of you and ME. Let's consume and apply this 'actionable pills' in our daily life ^^ > https://taplink.cc/actionpills <

No responses yet