- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello guys, I want to convert decimal from dec_buffer to a bin_buffer.
Example: dec_buffer[1]=1; bin_buffer[1][12]={000000000001}; dec_buffer[2]=2; bin_buffer[2][12]={000000000010}; dec_buffer[3]=3; bin_buffer[3][12]={000000000011};and soon The error is at "bin_buffer[buf_num] = show_binary(dec_buffer[buf_num]);" ; Error: incompatible types in assignment I think it's a newbie question since I am a newbie on C programming, so please give me a hint :) NB:If there's any undeclared constant, please ignore it since i didn't copy all of my code here. I copied the part with issues only.# include <stdio.h>
# define BUFFER_NUM_MAX 192 //16*12# define BIT_NUM_MAX 12 //12bit
int dec_buffer;
int bin_buffer;
int bit_num;
int buf_num;
int show_binary(int num){
int j,b={0};
printf("data converted: %d ; binary: ",num);
for (j=1;j<=BIT_NUM_MAX;j++){
b=num%2;
num=num/2;
}
for(j=0;j<BIT_NUM_MAX;j++){
printf("%d",b);
}
printf("\n");
return b;
}
int main(void){
for (buf_num=1;buf_num<=BUFFER_NUM_MAX;buf_num++){
dec_buffer = buf_num;
bin_buffer = show_binary(dec_buffer);//Error: incompatible types in assignment
}
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If it's about the different array dimension, I have tried below code,but no luck.
int show_binary(int num){
int j,b;
printf("data converted: %d ; binary: ",num);
for (j=1;j<=BIT_NUM_MAX;j++){
b=num%2;
num=num/2;
}
for(j=0;j<BIT_NUM_MAX;j++){
printf("%d",b);
}
printf("\n");
return b;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I highlighted some error register. And print out the converted(decimal to binary) buffers, I got the value I wanted, but the problem is i want to save the value to bin_buffer since I will need them for further process.
My current objective is : if dec_buffer[1] = 1 ; bin_buffer[1][11] ~ bin_buffer[1][1] = 0 and bin_buffer[1][0] = 1; if dec_buffer[2] = 2 ; bin_buffer[1][11] ~ bin_buffer[1][2] = 0 , bin_buffer[1][1] = 1; bin_buffer[1][1] = 0; and soon.. Need some help here :) Thank you :D# include <stdio.h>
# define BUFFER_NUM_MAX 192 //16*12# define BIT_NUM_MAX 12 //12bit
int dec_buffer;
int bin_buffer;
int bit_num;
int buf_num;
int show_binary(int num){
int j,b={0};
printf("data converted: %d ; binary: ",num);
for (j=1;j<=BIT_NUM_MAX;j++){
b=num%2;
num=num/2;
}
for(j=0;j<BIT_NUM_MAX;j++){
printf("%d",b);
}
printf("\n");
return b;
}
int main(void){
for (buf_num=1;buf_num<=BUFFER_NUM_MAX;buf_num++){
dec_buffer = buf_num;
/*bin_buffer = */show_binary(dec_buffer);//Error: incompatible types in assignment
}
binary_error.jpg
(Virus scan in progress ...)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
problem solved. thank you

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page