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

convert negative numbers to binary

769 views
Skip to first unread message

Ashwini Deshpande

unread,
Aug 22, 2009, 1:21:01 AM8/22/09
to
Hi,

How do i covert negative decimal numbers into binary??. For example,
a=[-5.5 -2 1.0 3.2 -6.3]; to equivalent binary.

I tried to convert them to 2's complement as follows:
a=-5;
b=dec2bin(2^4+a);
this works fine for the numbers without decimal point.

Can anyone tell me how to do the conversion with decimal point.

Thanks !
Ashwini

James Tursa

unread,
Aug 22, 2009, 2:28:03 AM8/22/09
to
"Ashwini Deshpande" <vd.as...@mathworks.com> wrote in message <h6nv7t$f4j$1...@fred.mathworks.com>...

2's complement is a scheme used for storing integers. What, exactly, would you expect such a scheme to do with fractional inputs?

James Tursa

Ashwini Deshpande

unread,
Aug 22, 2009, 3:28:03 AM8/22/09
to
"James Tursa" <aclassyguy_wi...@hotmail.com> wrote in message <h6o35j$kcd$1...@fred.mathworks.com>...

Thanks !
I want binary equivalent of any negative decimal integer. For Ex: -5.5.

How do i do this ??

Thanks,
Ashwini

Matt

unread,
Aug 22, 2009, 6:37:02 AM8/22/09
to
"Ashwini Deshpande" <vd.as...@mathworks.com> wrote in message <h6o6m3$3ko$1...@fred.mathworks.com>...

> Thanks !
> I want binary equivalent of any negative decimal integer. For Ex: -5.5.


But how would you define 2's complement for non-integer quantities?
In your example, what would the binary representation of -5.5 be?

Ashwini Deshpande

unread,
Aug 22, 2009, 7:36:01 AM8/22/09
to
"Matt " <x...@whatever.com> wrote in message <h6ohoe$bmm$1...@fred.mathworks.com>...

that is what i am looking for ..
for only negative quantities i followed the step mentioned below:
a=-5;
b=dec2bin(2^4+a);

how about negative decimail.
Requirement is that, i have FSK modulate sound file (.wav) which will have both positive and negative decimals .. how do i convert them into equivalent binary data?? whithout converting them into zeros and ones i can not modulate.

Any idea ???

Thanks !
Ashwini

Matt

unread,
Aug 22, 2009, 11:24:02 AM8/22/09
to
"Ashwini Deshpande" <vd.as...@mathworks.com> wrote in message <h6ol71$76j$1...@fred.mathworks.com>...

> > But how would you define 2's complement for non-integer quantities?
> > In your example, what would the binary representation of -5.5 be?
>
> that is what i am looking for ..
> for only negative quantities i followed the step mentioned below:
> a=-5;
> b=dec2bin(2^4+a);
>
> how about negative decimail.
> Requirement is that, i have FSK modulate sound file (.wav) which will have both positive and negative decimals .. how do i convert them into equivalent binary data?? whithout converting them into zeros and ones i can not modulate.

================================

Could you pre-scale all of your decimals to make them integer. For example, all of your example data had a single decimal point, so you could pre-convert them to intergers by multiplying them all by 10. Then you could convert them to binary as above and, if need be, unscale them later at the end of your processing chain.

Ashwini Deshpande

unread,
Aug 24, 2009, 12:23:04 AM8/24/09
to
"Matt " <x...@whatever.com> wrote in message <h6p2ii$967$1...@fred.mathworks.com>...

Thanks Matt,
Is is very good idea .. let me try it out and check how faithfully i can get back my voice signal after demodulation.

Ashwini

Ashwini Deshpande

unread,
Aug 25, 2009, 1:24:02 AM8/25/09
to
"Ashwini Deshpande" <vd.as...@mathworks.com> wrote in message <h6t4j8$7dn$1...@fred.mathworks.com>...

Hey Matt,
It works well, thanks a lot ...
(The demodulated wave is almost resembling the original wave)

Ashwini

ashish mahaju

unread,
Jul 9, 2017, 11:57:15 AM7/9/17
to
"Ashwini" wrote in message <h6vshi$eik$1...@fred.mathworks.com>...
ashwini can you share the code how u did it?
0 new messages