Showing results for

- Intel Community
- FPGAs and Programmable Solutions
- Nios® II Embedded Design Suite (EDS)
- Convert binary ( integer and fraction) from vhdl to decimal in C code,negative value

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

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-28-2015
11:58 AM

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
Link Copied

0 Replies

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

For more complete information about compiler optimizations, see our Optimization Notice.