Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12590 Discussions

Convert binary ( integer and fraction) from vhdl to decimal in C code,negative value

Altera_Forum
Honored Contributor II
1,544 Views

HI, 

 

 

I learned from this link (http://stackoverflow.com/questions/15767758/correct-algorithm-to-convert-binary-floating-point-1101-11-into-decimal-13-75) that I could convert a binary (consists of both integer and fraction) to decimal values. 

 

 

I am wondering if this code can be used to check for negative value? I did try with a binary string of 11111101.11 and it gives the output of 253.75... 

 

 

I have two questions: 

 

 

What are the modifications I need to do in order to read a negative value? 

I know that I can do the bit shift (as below) to check if the msb is 1, if it is 1, I know it is negative value... 

 

 

if (14bit_data & 0x2000) //if true, it is negative value 

 

The issue is, since it involves fraction part (but not only integer), it confused me a bit if the method still works... 

 

 

If the binary number is originally not in string format, is there any way I could convert it to string? The binary number is originally fed from a fpga block say, 14 bits, with msb as the sign bit, the following 6 bits are the magnitude for integer and the last 6 bits are the magnitude for fractional part. 

 

 

Any idea please? Thank you in advance
0 Kudos
0 Replies
Reply