Hi i'm trying to find binary value of every element of array and to set it in 2d array. Here is my code:
#include <iostream>
void tobin(int a,int b[]);
int main()
{
int i,j;
int b[8];//bin array
int d[3][8]; //2d array
int c[3] = {6,15,24}; //int array
//My code for transformation from array to 2d array
for(i=0;i<3;i++)
{
tobin(c[i],b);
for(j=0;j<8;j++)
{
d[i][j]=b[j];
}
}
//Printing of 2d array
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
std::cout<<d[i][j];
std::cout<<std::endl;
}
}
//Function for convert int to bin
void tobin(int a,int b[])
{
int i;
for(i=0;i<8;i++)
{
b[i]=a%2;
a/=2;
}
}
And here my output:
01100000
11110000
00011000
00-16437331793270200193648149632765
014196397000-640061051-1985511146
419616001936481488327650000
16416403251985832910-46743922719940467470000
004196848019364814963276510
First 3 lines is what i was looking for, but i don't know what is the rest. Can someone help me to fix this. And to give me explanation why is this happening or link to explanation.