Convert words to binary values - c

I need to convert words to binary numbers, positioned vertically (\n).
I need to write a function, which will do this convert.. Below is a sample..
Can you help me please?
//main
char* text = "Hello, how are you?";
const int len = strlen(text);
bool bytes1[len+1][8];
encode_string(text, bytes1);
for(int j = 0; j <= len; j++){
printf("%c: ", text[j]);
for(int i = 0; i < 8; i++){
printf("%d", bytes1[j][i]);
}
printf("\n");
}
// prints:
// H: 01001000
// e: 01100101
// l: 01101100
// l: 01101100
// o: 01101111
// ,: 00101100
// : 00100000
// h: 01101000
// o: 01101111
// w: 01110111
// : 00100000
// a: 01100001
// r: 01110010
// e: 01100101
// : 00100000
// y: 01111001
// o: 01101111
// u: 01110101
// ?: 00111111
// : 00000000
//function
void encode_string(const char string[], bool bytes[strlen(string)+1][8]){
}

Hy man you can use this:
Converting every char:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
int main(void){
char* text = "Hello, how are you?";
int len_size = strlen(text);
for(int j = 0; j <= len_size; j++){
printf("%c: ", text[j]);
for( int i = 7; i >= 0; i-- ) {
printf( "%d", ( text[j] >> i ) & 1 ? 1 : 0 );
}
printf("\n");
}
return 0;
}
Onother option with your function:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
void encode_string(char string[], int len_size);
int main(void){
char* text = "Hello, how are you?";
int len_size = strlen(text);
encode_string(text, len_size);
return 0;
}
void encode_string(char string[], int len_size){
for(int j = 0; j <= len_size; j++){
printf("%c: ", string[j]);
for( int i = 7; i >= 0; i-- ) {
printf( "%d", ( string[j] >> i ) & 1 ? 1 : 0 );
}
printf("\n");
}
}
I know your error already, your are trying to send to the function, and you dont send the right parameters...

Related

How convert string to binary

Im cant understand whats wrong with my code. All start to work good, but when my phrase "Hello, how are you" compiled, it start to print some other numbers and symbols.
Thank you in advance!your text
include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
void encode_string(const char string[], bool bytes[strlen(string)+1][8]){
for(int j = 0; j <= bytes[strlen(string)+1][8]; j++){
printf("%c: ", string[j]);
for( int i = 7; i >= 0; i-- ) {
printf( "%d", ( string[j] >> i ) & 1 ? 1 : 0 );
}
printf("\n");
}
}
int main(){
char* text = "Hello, how are you?";
const int len = strlen(text);
bool bytes1[len+1][8];
encode_string(text, bytes1);
for(int j = 0; j <= len; j++){
printf("%c: ", text[j]);
for(int i = 0; i < 8; i++){
printf("%d", bytes1[j][i]);
}
printf("\n");
}
}
You're not allocating memory to string which you are passing. which leads to UB. I removed string size parameter in function encode_string
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
void encode_string(const char string[])
{
size_t len = strlen(string);
char *binary = malloc(len*8 + 1); //each char is one byte (8 bits) and + 1 at the end for null terminator
for(int j = 0; j <= len; j++){
printf("%c: ", string[j]);
for( int i = 7; i >= 0; i-- ) {
printf( "%d", ( string[j] >> i ) & 1 ? 1 : 0 );
}
printf("\n");
}
}
int main(){
char* text = "Hello, how are you?";
const int len = strlen(text);
bool bytes1[len+1][8];
encode_string(text);
for(int j = 0; j <= len; j++){
printf("%c: ", text[j]);
for(int i = 0; i < 8; i++){
printf("%d", bytes1[j][i]);
}
printf("\n");
}
}
Output:
H: 01001000
e: 01100101
l: 01101100
l: 01101100
o: 01101111
,: 00101100
: 00100000
h: 01101000
o: 01101111
w: 01110111
: 00100000
a: 01100001
r: 01110010
e: 01100101
: 00100000
y: 01111001
o: 01101111
u: 01110101
?: 00111111
: 00000000
H: 192900192900
e: 192900192900
l: 192900192900
l: 192900192900
o: 192900192900
,: 192900192900
: 192900192900
h: 192900192900
o: 00000000
w: 010064000
: 000064000
a: 02000400
r: 00000000
e: 00000000
: 00000000
y: 00000000
o: 00000000
u: 00000000
?: 00000000
: 2151941531301348500
...Program finished with exit code 0
Press ENTER to exit console.

A Problem I faced using Bitwise Operators in C (HackerRank)

HackerRank link
In this challenge, you will use logical bitwise operators. All data is stored in its binary representation. The logical operators, and C language, use 1 to represent true and 0 to represent false. The logical operators compare bits in two numbers and return true or false, 0 or 1, for each bit compared.
Bitwise AND operator & The output of bitwise AND is 1 if the corresponding bits of two operands is 1. If either bit of an operand is 0, the result of corresponding bit is evaluated to 0. It is denoted by &.
Bitwise OR operator | The output of bitwise OR is 1 if at least one corresponding bit of two operands is 1. It is denoted by |.
Bitwise XOR (exclusive OR) operator ^ The result of bitwise XOR operator is 1 if the corresponding bits of two operands are opposite. It is denoted by ^.
For example, for integers 3 and 5,
3 = 00000011 (In Binary)
5 = 00000101 (In Binary)
AND operation OR operation XOR operation
00000011 00000011 00000011
& 00000101 | 00000101 ^ 00000101
________ ________ ________
00000001 = 1 00000111 = 7 00000110 = 6
you will be given an integer n and a threshold, k. For each number, find the maximum value of the logical and,or and xor when compared against all integers through n.
Example
n=3
k=3
The Results of the comparisons are below:
a b and or xor
1 2 0 3 3
1 3 1 3 2
2 3 2 3 1
For the and comparison, the maximum is 2. For the or comparison, none of the values is less than k, so the maximum is 0. For the xor comparison, the maximum value less than k is 2. The function should print:
2
0
2
Function Description
Complete the calculate_the_maximum function in the editor below.
calculate_the_maximum has the following parameters:
int n: the highest number to consider
int n: the highest number to consider
Prints
Print the maximum values for the and, or and xor comparisons, each on a separate line.
Input Format
The only line contains 2 space-separated integers, n and k.
Constraints
2 <= n <= (10)^3
2 <= k <= n
Sample Input 0
5 4
*Sample Output 0
2
3
3
** So This is My Answer**
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
void calculate_the_maximum(int n, int k) {
int m1=0,m2=0,m3=0;
for (int x=1; x<n; x++){
for (int y=2; y<=n; y++){
//and
int a=x&y;
if((a>m1) && (a<k)){
m1=a;
};
//or
int b=x|y;
if((b>m2) && (b<k)){
m2=b;
};
//xor
int c=x^y;
if((c>m3) && (c<k)){
m3=c;
};
}
}
printf("%d \n",m1);
printf("%d \n",m2);
printf("%d \n",m3);
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
calculate_the_maximum(n, k);
return 0;
}
And My Output is
3
3
3
Expected Output
2
3
3
What is the mistake of my code?
This was my answer
I first converted to binary then converted it back
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
//Complete the following function.
void calculate_the_maximum(int n, int k)
{
int i,j,a,b;
int max_and = 0;
int max_or = 0;
int max_xor = 0;
for (i = 1; i < n+1; i++)
{
for (j = 1; j < n+1; j++)
{
if (j>i)
{
a = i;
b = j;
int count_1 = 0;
int sum_1 = 0;
int count_2 = 0;
int sum_2 = 0;
while (!(a==0))
{
sum_1 += (a%2)*(pow(10,count_1));
a = a/2;
count_1++;
}
while (!(b==0))
{
sum_2 += (b%2)*(pow(10,count_2));
b = b/2;
count_2++;
}
int sum_3 = 0;
int sum_4 = 0;
int sum_5 = 0;
int num_1 = 0;
int num_2 = 0;
int num_3 =0;
int count_3 = 0;
while (!((sum_1 == 0)&&(sum_2 == 0)))
{
if ((sum_1%10 == 1)&&(sum_2%10 == 1))
{
sum_3 += pow(10,count_3);
}
if ((sum_1%10 == 1)||(sum_2%10 == 1))
{
sum_4 += pow(10,count_3);
}
if (((sum_1%10 == 1)&&(sum_2%10 == 0))||((sum_1%10 == 0)&&(sum_2%10 == 1)))
{
sum_5 += pow(10,count_3);
}
sum_1 = sum_1/10;
sum_2 = sum_2/10;
count_3++;
}
int count_4 = 0;
while (!(sum_3 == 0))
{
num_1 += (sum_3%10)*(pow(2,count_4));
sum_3 = sum_3/10;
count_4++;
}
int count_5 = 0;
while (!(sum_4 == 0))
{
num_2 += (sum_4%10)*(pow(2,count_5));
sum_4 = sum_4/10;
count_5++;
}
int count_6 = 0;
while (!(sum_5 == 0))
{
num_3 += (sum_5%10)*(pow(2,count_6));
sum_5 = sum_5/10;
count_6++;
}
if ((max_and < num_1)&&(num_1<k))
{
max_and = num_1;
}
if ((max_or < num_2)&&(num_2<k))
{
max_or = num_2;
}
if ((max_xor < num_3)&&(num_3<k))
{
max_xor = num_3;
}
}
}
}
printf("%d\n%d\n%d",max_and,max_or,max_xor);
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
if (!((n < 2)||(n > 1000)||(k < 2)||(k >n)))
{
calculate_the_maximum(n, k);
return 0;
}
else
{
printf("Error!\n");
return 1;
}
}
You shouldn't initialize "y" at 2. In your case, i and y can be the same values.
when i = 2, y can be equal to 2. But you cannot do this for the question. Start y from i+1.
void calculate_the_maximum(int n, int k)
{
int max_or = 0;
int max_and = 0;
int max_xor = 0;
int temp_xor = 0;
int temp_and = 0;
int temp_or = 0;
//or = xor + and;
for(int i = 1 ; i < n ; i++ )
{
for(int j = i+1 ; j <=n ; j++)
{
temp_xor = i ^ j;
temp_and = i & j;
temp_or = temp_xor + temp_and;
if (temp_xor > max_xor && temp_xor < k) max_xor = temp_xor;
if (temp_and > max_and && temp_and < k) max_and = temp_and;
if (temp_or > max_or && temp_or < k) max_or = temp_or;
}
}
//print
cout << max_and << endl << max_or << endl << max_xor;
}
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
void calculate_the_maximum(int n, int k) {
int m1=0,m2=0,m3=0;
for (int x=1; x<n; x++){
for (int y=x+1; y<=n; y++){
//and
int a= x & y;
if((a>m1) && (a<k)){
m1=a;
};
//or
int b=x|y;
if((b>m2) && (b<k)){
m2=b;
};
//xor
int c=x^y;
if((c>m3) && (c<k)){
m3=c;
};
}
}
printf("%d \n",m1);
printf("%d \n",m2);
printf("%d \n",m3);
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
calculate_the_maximum(n, k);
return 0;
}

Bitwise Operators wrong output

Problem : https://www.hackerrank.com/challenges/bitwise-operators-in-c/problem
I tried the problem using C but the output comes out to be
1
5
1
instead of
2
3
3
I cant find the fault in this code:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
//Complete the following function.
void calculate_the_maximum(int n, int k)
{
int answer1=0;
int answer2=0;
int answer3=0;
for(int i=1;i<n;i++)
{
for(int j=i+1; j<=n;j++)
{
if((i&j >=answer1) && (i&j < k))
{
answer1 = (i&j);
}
if((i|j >=answer2) && (i|j < k))
{
answer2 = (i|j);
}
if((i^j >=answer3) && (i^j < k))
{
answer3 = (i^j);
}
}
}
printf("%d\n%d\n%d",answer1,answer2,answer3);
}
int main()
{
int n, k;
scanf("%d %d", &n, &k);
calculate_the_maximum(n, k);
return 0;
}
I don't like putting complete answeres but since I had it solved i hope it can help you.
I broke it down so it will be easier to understand
watch the shortened if statment (condition) ? True_val : False_val
void calculate_the_maximum(int n, int k) {
int max_and = 0;
int max_or = 0;
int max_xor = 0;
int tOr, tAnd, tXor;
for (int i = 1; i <= n ; i++)
for (int j = 1; j <= n; j++) {
if ( i <= j ) continue;
tAnd = (i & j);
tOr = (i | j);
tXor = (i ^ j);
max_and = ((tAnd > max_and) && (tAnd <k)) ? tAnd : max_and;
max_or = ((tOr > max_or) && (tOr <k)) ? tOr : max_or;
max_xor = ((tXor > max_xor) && (tXor < k)) ? tXor : max_xor;
}
printf("%d\n%d\n%d", max_and, max_or, max_xor);
}

Algorithm for searching unique elements combinations in C (elements position in resulting string doesn't matter)

I have code for char array unique elements searching. But it works incorrectly. For example, in case of "ABCD" array, I lose "ABD" case. How can I fix it?
#include <stdio.h>
#include <string.h>
void fun(char *str, int size, int depth)
{
int i = 0;
int j = 0;
int k = 0;
while (i < size - depth + 1)
{
j = i + 1;
while (j < size - depth + 2)
{
printf("%c", str[i]);
k = j;
while (k < j + depth - 1)
{
printf("%c", str[k]);
k++;
}
printf("\n");
j++;
}
i++;
}
}
int main(void)
{
char *str = "ABCD";
int i = 0;
while (i < strlen(str))
{
fun(str, strlen(str), i + 1);
i++;
}
return (0);
}
The result is: A A A A B B B C C D AB AC AD BC BD CD ABC ACD BCD ABCD
And I need: A B C D AB AC AD BC BD CD ABC ABD ACD BCD ABCD
So as you can see there are several bugs - repeats of single chars at the beginning and missing ABD case. If the string is "ABCDE" there are more variants will be missing.
This code should fix the problem:
#include <string.h>
#include <stdio.h>
void fun(char *str, char *data, int start, int end, int idx, int depth)
{
if (idx == depth)
{
for (int j = 0; j < depth; j++)
printf("%c", data[j]);
printf("\n");
return;
}
for (int i = start; i <= end && end - i + 1 >= depth - idx; i++)
{
data[idx] = str[i];
fun(str, data, i + 1, end, idx + 1, depth);
}
}
int main()
{
char *str = "ABCD";
int i = 0;
while (i < strlen(str))
{
char data[i + 1];
fun(str, data, 0, strlen(str) - 1, 0, i + 1);
i++;
}
return (0);
}
Output:
A
B
C
D
AB
AC
AD
BC
BD
CD
ABC
ABD
ACD
BCD
ABCD
And also works for "ABCDE" and etc.

Generate all binary strings of length n with k bits set.(need to write on C)

Please help me to solve this task:
Generate all binary strings of length n with k bits set.(need to write on C)
for example:
n=5
k=3
11100
00111
11010
01011
**01110
11001
10011
**01101
**10110
10101
** can't generate these permutations
Code:
#include <stdio.h>
#define N 10
int main (void)
{
int mas[N]={0},kst,m,n1,z,a,b;
printf("\n\nVvedit` rozmirnist` masyvu: ");
scanf("%d",&kst);
printf("\n\nVvedit` kil`kist` odynyc`: ");
scanf("%d",&n1);
for(m=0;m1;m++)
mas[m]=1;
for(m=0;m<kst;m++)
printf("%d",mas[m]);
printf("\n");
for(m=0;m<n1;m++){
for(z=0;z<(kst-1);z++)
if((mas[z]==1) && (mas[z+1]==0)){
a=mas[z];
mas[z]=mas[z+1];
mas[z+1]=a;
for(b=0;b<kst;b++)
printf("%d",mas[b]);
printf("\n");
}
}
return 0;
}
I have solved this problem earlier! please find my code below! I hope this will help you out.
#include<stdio.h>
int NumberOfBitsSet(int number)
{
int BitsSet = 0;
while(number != 0)
{
if(number & 0x01)
{
BitsSet++;
}
number = number >> 1;
}
return BitsSet;
}
void PrintNumberInBinary(int number, int NumBits)
{
int val;
val = 1 << NumBits; // here val is the maximum possible number of N bits with only MSB set
while(val != 0)
{
if(number & val)
{
printf("1");
}
else
{
printf("0");
}
val = val >> 1;
}
}
int main()
{
int n,k,i;
int max,min;
printf("enter total number of bits and number of bits to be set:\n");
scanf("%d %d", &n, &k);
min = ((1 << k) - 1); //min possible values with k bits set
max = (min << (n-k)); //max possible value with k bits set!
//printf("%d %d", min, max);
for(i=0; i<= max; i++)
{
if(!(i<min))
{
if(NumberOfBitsSet(i) == k)
{
PrintNumberInBinary(i, (n-1));
printf("\n");
}
}
}
return 0;
}
Your code is a mess ;)
Seriously: first rule when solving a task in code is to write clean code, use sensible variable naming etc.
For tasks like this one I would suggest using this.
Now to your sample code: it would not compile and it is hard to read what you are trying to do. Formatted and with some comments:
#include <stdio.h>
#define N 10
int main(void)
{
int mas[N] = {0};
int kst, m, n1, z, a, b;
/* Read width ? */
printf("\n\nVvedit` rozmirnist` masyvu: ");
scanf("%d", &kst);
/* Read number of bit's set? */
printf("\n\nVvedit` kil`kist` odynyc`: ");
scanf("%d", &n1);
/* m1 is not defined, thus the loop give no meaning.
* Guess you are trying to set "bits" integers to 1.
*/
for (m = 0; m1; m++)
mas[m] = 1;
/* This should be in a function as 1. You do it more then once, and
* 2. It makes the code much cleaner and easy to maintain.
*/
for (m = 0; m < kst; m++)
printf("%d", mas[m]);
printf("\n");
for (m = 0; m < n1; m++) {
for (z = 0; z < (kst - 1); z++) {
if ((mas[z] == 1) && (mas[z + 1] == 0)) {
a = mas[z]; /* Same as a = 1; */
mas[z] = mas[z + 1]; /* Same as mas[z] = 0; */
mas[z + 1] = a; /* Same as mas[z + 1] = 1; */
/* Put this into a function. */
for (b = 0; b < kst; b++)
printf("%d", mas[b]);
printf("\n");
}
}
}
return 0;
}
The extensive use of printf when one are not sure of what is going on is a precious tool.
This is not a solution, (it is basically doing the same as your post, but split up), but a sample of something that might be easier to work with. I have also used a char array as C-string instead of integer array. Easier to work with in this situation.
If you want to use integer array I'd suggest you add a print_perm(int *perm, int width) helper function to get it out of the main code.
#include <stdio.h>
#define MAX_WIDTH 10
int get_spec(int *width, int *bits)
{
fprintf(stderr, "Enter width (max %-2d): ", MAX_WIDTH);
scanf("%d", width);
if (*width > MAX_WIDTH) {
fprintf(stderr, "Bad input: %d > %d\n", *width, MAX_WIDTH);
return 1;
}
fprintf(stderr, "Enter set bits (max %-2d): ", *width);
scanf("%d", bits);
if (*bits > MAX_WIDTH) {
fprintf(stderr, "Bad input: %d > %d\n", *bits, MAX_WIDTH);
return 1;
}
return 0;
}
void permutate(int width, int bits)
{
char perm[MAX_WIDTH + 1];
int i, j;
/* Set "bits" */
for (i = 0; i < width; ++i)
perm[i] = i < bits ? '1' : '0';
/* Terminate C string */
perm[i] = '\0';
fprintf(stderr, "\nPermutations:\n");
printf("%s\n", perm);
for (i = 0; i < bits; ++i) {
/* Debug print current perm and outer iteration number */
printf("%*s LOOP(%d) %s\n",
width, "", i, perm
);
for (j = 0; j < (width - 1); ++j) {
if (perm[j] == '1' && perm[j + 1] == '0') {
perm[j] = '0';
perm[j + 1] = '1';
printf("%s j=%d print\n",
perm, j
);
} else {
/* Debug print */
printf("%*s j=%d skip %s\n",
width, "", j, perm
);
}
}
}
}
int main(void)
{
int width, bits;
if (get_spec(&width, &bits))
return 1;
permutate(width, bits);
return 0;
}
If you want to list all of the permutations uniquely without doing "iterate and check", you can do something like this:
# Move peg x up m using s
# x is negative
# m is positive
def move(x, m, s):
for i in range(1, m+1):
s2 = list(s)
s2[x] = 0
s2[x - i] = 1
print(s2)
if x + 1 < 0:
move(x+1, i, s2)
# Print all unique permutations of
# n bits with k ones (and n-k zeros)
def uniqPerms(n, k):
s = [0 for _ in range(n-k)] + [1 for _ in range(k)]
print(s)
move(-k, n-k, s)
if __name__ == '__main__':
from sys import argv
uniqPerms(int(argv[1]), int(argv[2]))
The idea is that you inch the 1's up recursively, so that each movement produces a unique list (since a 1 is now somewhere none was before).
And you said it must be in C:
#include <stdio.h>
#include <stdlib.h>
enum { n = 8 };
struct string
{
char str[n + 1];
};
void move(int x, int m, string s)
{
for (int i = 0; i <= m; ++i)
{
string s2 = s;
s2.str[n + x] = '0';
s2.str[n + x - i] = '1';
printf("%s\n", s2.str);
if (x + 1 < 0)
move(x + 1, i, s2);
}
}
void uniqPerms(int k)
{
string s;
for (int i = 0; i < n - k; ++i)
s.str[i] = '0';
for (int i = n - k; i < n; ++i)
s.str[i] = '1';
s.str[n] = '\0';
printf("%s\n", s.str);
move(-k, n - k, s);
}
int main(int argc, char *argv[])
{
uniqPerms(atoi(argv[1]));
return 0;
}
try this
A[n-1]=0;
func(n-1);
A[n-1]=1;
func(n-1);
//Think simple people but please bear with me i love java
//Assume array A is globally defined
void Binary(int n)
{
if(n<1)
{
System.out.println(A);
}
else
{
A[n-1]=0;
Binary(n-1);
A[n-1]=1;
Binary(n-1);
}
}
here is the recursive solution
#include <iostream>
#include <vector>
using namespace std;
char v[4];
int count = 0;
void printString(){
int i;
for(i = 0; i < 4; i++){
cout << v[i] << " ";
}
cout <<count << endl;
}
void binary(int n){
if(n < 0){
if(count == 2)
printString();
}
else{
v[n] = '0';
binary(n - 1);
v[n] = '1';
count++;
binary(n-1);
count--;
}
}
int main(){
binary(3);
return 0;
}
#include<stdio.h>
int main(){
int n,k,i,j,a[50];
//lets suppose maximum size is 50
printf("Enter the value for n");
scanf("%d",&n);
printf("Enter the value for k");
scanf("%d",&k);
//create an initial bitstring of k 1's and n-k 0's;
for(i=0;i<n;i++){
if(k>0)
a[i]=1;
else
a[i]=0;
k--;
}
for(i=0;i<n;i++){
if(a[i]==1){
for(j=0;j<n;j++){
if(j!=i&&a[j]==0){
a[j]=1;a[i]=0;
for(k=0;k<n;k++){printf("%d\n",a[k]);}
a[i]=1; a[j]=0;
}}}}
return 0;
}
**If Complexity doesn't matter you can use the following code which are done in java. which will provide the desired output in o(2^n).Here I have find all the combination of 0 and 1 for the given n bits in array of size n.In case of K bit is set I have counted the number of 1 presented is equal to k using countBits() funtion.if so I have printed that array.
public class GenerateAllStringOfNBitsWithKBitsSet {
public static int a[] ={0,0,0,0,0};
static int k=3;
public static boolean countBits(){
int y=0;
for(int i=0;i<a.length;i++)
y += a[i] & 1 ;
if(y==k)
return true;
return false;
}
public static void gen(int n)
{
if(n<1)
{
if(countBits())
System.out.println(Arrays.toString(a));
}
else
{
a[n-1]=0;
gen(n-1);
a[n-1]=1;
gen(n-1);
}
}
public static void main(String[] args) {
GenerateAllStringOfNBitsWithKBitsSet.gen(a.length);
}
}

Resources