欢迎来到天天文库
浏览记录
ID:40816638
大小:20.96 KB
页数:8页
时间:2019-08-08
《十进制转二进制 C语言》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、/*十进制数据转化成二进制数据,可选择使用补码或源码*//*d_to_b.h*/#definedata_length79177#definedata_bit16//转化成二进制后的数据位宽#defineshift_length3//移位位宽#definecom_code0//取1则负数转化为补码#definecode~com_codedoubledata_in_i[data_length];//I路输入的十进制数据寄存器doubledata_in_q[data_length];//Q路输入的十进制数据寄存器intdata_reg_i[data_length];intd
2、ata_reg_q[data_length];intbinary_i[data_bit];//存放二进制数据的寄存器intbinary_q[data_bit];//存放二进制数据的寄存器intbinary_i_com[data_bit];//存放二进制补码数据的寄存器intbinary_q_com[data_bit];//存放二进制补码数据的寄存器/*d_to_b.c*/#include#include#include"d_to_b.h"/************************************************
3、******************十进制转化成二进制,且负数可选择用补码还是源码表示~~~~******************************************************************/intmain(){inti;intj,k;/*----------------------读入数据---------------------*/FILE*fp_in_i,*fp_in_q;fp_in_i=fopen("tx_interp_out_i.txt","r");fp_in_q=fopen("tx_interp_out_q.txt","
4、r");for(i=0;i5、t_out_q.txt","w+");FILE*fp_out_i,*fp_out_q;fp_out_i=fopen("change_out_i.txt","w+");fp_out_q=fopen("change_out_q.txt","w+");/*-------------需要移位的数据先进行移位,即转化成整数,不需要转的,则设置shift_length=0------------*/for(i=0;i6、_in_q[i]*pow(2,shift_length);fprintf(fp_shift_i,"%d",data_reg_i[i]);fprintf(fp_shift_q,"%d",data_reg_q[i]);}/*-----------------------------------------------*//*---------------------------十进制化为二进制,负数用补码--------------------------------*/#ifcom_codefor(i=0;i7、-------I路正数转化-------------*/if(data_reg_i[i]>=0){binary_i[data_bit-1]=0;//符号位为0fprintf(fp_out_i,"%d",binary_i[data_bit-1]);for(j=0,k=fabs(data_reg_i[i]);j=0;j--){fprintf(fp_out_i,"%d",binary_i[
5、t_out_q.txt","w+");FILE*fp_out_i,*fp_out_q;fp_out_i=fopen("change_out_i.txt","w+");fp_out_q=fopen("change_out_q.txt","w+");/*-------------需要移位的数据先进行移位,即转化成整数,不需要转的,则设置shift_length=0------------*/for(i=0;i6、_in_q[i]*pow(2,shift_length);fprintf(fp_shift_i,"%d",data_reg_i[i]);fprintf(fp_shift_q,"%d",data_reg_q[i]);}/*-----------------------------------------------*//*---------------------------十进制化为二进制,负数用补码--------------------------------*/#ifcom_codefor(i=0;i7、-------I路正数转化-------------*/if(data_reg_i[i]>=0){binary_i[data_bit-1]=0;//符号位为0fprintf(fp_out_i,"%d",binary_i[data_bit-1]);for(j=0,k=fabs(data_reg_i[i]);j=0;j--){fprintf(fp_out_i,"%d",binary_i[
6、_in_q[i]*pow(2,shift_length);fprintf(fp_shift_i,"%d",data_reg_i[i]);fprintf(fp_shift_q,"%d",data_reg_q[i]);}/*-----------------------------------------------*//*---------------------------十进制化为二进制,负数用补码--------------------------------*/#ifcom_codefor(i=0;i7、-------I路正数转化-------------*/if(data_reg_i[i]>=0){binary_i[data_bit-1]=0;//符号位为0fprintf(fp_out_i,"%d",binary_i[data_bit-1]);for(j=0,k=fabs(data_reg_i[i]);j=0;j--){fprintf(fp_out_i,"%d",binary_i[
7、-------I路正数转化-------------*/if(data_reg_i[i]>=0){binary_i[data_bit-1]=0;//符号位为0fprintf(fp_out_i,"%d",binary_i[data_bit-1]);for(j=0,k=fabs(data_reg_i[i]);j=0;j--){fprintf(fp_out_i,"%d",binary_i[
此文档下载收益归作者所有