Sitemap

#JavaSolved : Bitwise One

2 min readSep 24, 2022
Press enter or click to view image in full size

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