Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
918 Views

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

HI, 

 

 

I learned from this link (http://stackoverflow.com/questions/15767758/correct-algorithm-to-convert-binary-floating-point-1101-...) 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