Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

code to convert negative fractions to binary

537 views
Skip to first unread message

ANITHA SHUKLA

unread,
Apr 30, 2010, 12:07:04 PM4/30/10
to
Hello everyone,

am looking for the matlab code for converting NEGATIVE FRACTIONS TO BINARY.

example fractions like------
- 0.432937622070313, -0.131301879882813, -0.312225341796875.

so could any one plz help me out how to convert from negative fractions to binary.

James Tursa

unread,
Apr 30, 2010, 4:41:06 PM4/30/10
to
"ANITHA SHUKLA" <shukla...@gmail.com> wrote in message <hrev78$qop$1...@fred.mathworks.com>...

Convert them to binary *what*? They are already in memory in binary floating point format, so what do you mean by binary?

James Tursa

Walter Roberson

unread,
Apr 30, 2010, 11:35:14 PM4/30/10
to

The following will get you part-way there, but you need to be clear
about _which_ binary representation you want for your negative values.
Standard IEEE floating point representation uses the leading bit to
indicate whether the number as a whole is negative or not. But if all
you want is IEEE floating point representation, then you can use
num2hex() and then do a simple table lookup to convert each nibble to
binary.

http://groups.google.ca/group/comp.soft-sys.matlab/browse_thread/thread/80e519cbfc3b4a26/42663465ad67387d

ANITHA SHUKLA

unread,
May 5, 2010, 5:30:07 PM5/5/10
to
"ANITHA SHUKLA" <shukla...@gmail.com> wrote in message <hrev78$qop$1...@fred.mathworks.com>...

IN FIXED-POINT FORM
THE MAIN PROBLEM IS I NEED TO GENERATE THE RECEIVED SIGNAL STRENGTH(RSSI) OF 16-BIT IN FIXED POINT.

FOR SUPPOSE IF I GOT ADC VALUES BETWEEN -32768 TO +32767, ASSUME LIKE
-29312, -4565, 65433, 12345, -12343
THEN PLZ TELL ME HOW TO GET RSSI USING FIXED POINT ALGORITHM IN MATLAB

James Tursa

unread,
May 5, 2010, 7:19:04 PM5/5/10
to
"ANITHA SHUKLA" <shukla...@gmail.com> wrote in message <hrso0v$cp3$1...@fred.mathworks.com>...

Please give a specific example of inputs and outputs of what you would like.

James Tursa

Walter Roberson

unread,
May 5, 2010, 7:22:25 PM5/5/10
to

That's the opposite of your original question. In your original
question, you had fractions that you needed converted to binary, and in
this question you effectively have binary that you need to convert to
fractions.

Unfortunately, there are an infinite number of possible answers, as we
do not know where the decimal point has been fixed.

If the fixed point is immediately before the first bit of the 16 bits,
so that the range of values is from -1 to just a hair less than 1, then
just divide the 16 bit value by 32768 .

ImageAnalyst

unread,
May 5, 2010, 10:27:05 PM5/5/10
to
On May 5, 5:30 pm, "ANITHA SHUKLA" <shuklapat...@gmail.com> wrote:
> FOR SUPPOSE IF I GOT ADC VALUES BETWEEN -32768 TO +32767, ASSUME LIKE
>   -29312, -4565, 65433, 12345, -12343
--------------------------------
And how is 65433 between -32768 and +32767?

I agree with the others that there is not enough info. Even if you
did supply it, it's so trivial (simple scaling and offsetting) that
I'm not sure where your difficulty comes in.

0 new messages