The Best Cyprus Community

Skip to content


How can I Convert negative decimal to binary

Feel free to talk about anything that you want.

How can I Convert negative decimal to binary

Postby Acunga » Mon Oct 29, 2007 7:07 pm

Can someone give me an algorythm fo this operation?
Acunga
Member
Member
 
Posts: 71
Joined: Fri May 25, 2007 12:18 pm

Postby Get Real! » Mon Oct 29, 2007 9:22 pm

Consider 8bit numbers...

1 2 3 4 5 6 7 8 (<--bit number)
-----------------------
0 1 1 1 1 0 1 0 (<-- the number 58 )

The LEFT-MOST bit (bit 1) is the MSB and NOT used so by setting bit 1 to...

"0" the number becomes positive and by setting it to "1" the number becomes nagative so to represent -58 we now have...

1 1 1 1 1 0 1 0 (<-- the number -58 )

So what you need is to write TWO ROUTINES...

1. Convert from Dec to Bin
2. Set bits on/off.

Happy with the theory so far? :D
User avatar
Get Real!
Forum Addict
Forum Addict
 
Posts: 48333
Joined: Mon Feb 26, 2007 12:25 am
Location: Nicosia

Postby Hazza » Mon Oct 29, 2007 9:54 pm

Lets try again...

01010100 01101000 01101001 01110011 00100000 01100011 01101111 01110101 01101100 01100100 00100000 01100010 01100101 00100000 01100110 01110101 01101110 00100000 01100001 01101110 01101110 01101111 01111001 01101001 01101110 01100111 00100000 01101111 01110100 01101000 01100101 01110010 01110011 00100000 01110111 01101001 01110100 01101000 00100000 01100010 01101001 01101110 01100001 01110010 01111001 00100000 01101101 01100101 01110011 01110011 01100001 01100111 01100101 01110011 00100001
User avatar
Hazza
Regular Contributor
Regular Contributor
 
Posts: 2383
Joined: Wed Mar 23, 2005 6:24 pm
Location: Larnaka.. Rating: Very Sexy

Postby Get Real! » Mon Oct 29, 2007 9:58 pm

Hazza wrote:Lets try again...

01010100 01101000 01101001 01110011 00100000 01100011 01101111 01110101 01101100 01100100 00100000 01100010 01100101 00100000 01100110 01110101 01101110 00100000 01100001 01101110 01101110 01101111 01111001 01101001 01101110 01100111 00100000 01101111 01110100 01101000 01100101 01110010 01110011 00100000 01110111 01101001 01110100 01101000 00100000 01100010 01101001 01101110 01100001 01110010 01111001 00100000 01101101 01100101 01110011 01110011 01100001 01100111 01100101 01110011 00100001


:shock: MASTER!!!
User avatar
Get Real!
Forum Addict
Forum Addict
 
Posts: 48333
Joined: Mon Feb 26, 2007 12:25 am
Location: Nicosia

Postby Sotos » Mon Oct 29, 2007 10:03 pm

User avatar
Sotos
Leading Contributor
Leading Contributor
 
Posts: 11357
Joined: Wed Aug 17, 2005 2:50 am

Postby Get Real! » Mon Oct 29, 2007 10:05 pm

Sotos wrote:http://www.wikihow.com/Convert-from-Decimal-to-Binary ;)


He specifically asked for NEGATIVE conversions! :wink:
User avatar
Get Real!
Forum Addict
Forum Addict
 
Posts: 48333
Joined: Mon Feb 26, 2007 12:25 am
Location: Nicosia

Postby Sotos » Mon Oct 29, 2007 10:07 pm

User avatar
Sotos
Leading Contributor
Leading Contributor
 
Posts: 11357
Joined: Wed Aug 17, 2005 2:50 am

Postby Hazza » Mon Oct 29, 2007 10:11 pm

Get Real! wrote:
:shock: MASTER!!!


Code: Select all
01001110 01101111 01110000 01100101 00101100 00100000 01110101 01110011 01101001 01101110 01100111 00100000 01110100 01101000 01101001 01110011 00100000 01110111 01100101 01100010 01110011 01101001 01110100 01100101 00100000 01110100 01101111 00100000 01100011 01101111 01101110 01110110 01100101 01110010 01110100 00100000 01100110 01101111 01110010 00100000 01101101 01100101 00101110 00001101 00001010 00001101 00001010 01101000 01110100 01110100 01110000 00111010 00101111 00101111 01110111 01110111 01110111 00101110 01101110 01101001 01100011 01101011 01100011 01101001 01110011 01101011 01100101 00101110 01100011 01101111 01101101 00101111 01110100 01101111 01101111 01101100 01110011 00101111 01100010 01101001 01101110 01100001 01110010 01111001 00101110 01110000 01101000 01110000 00001101 00001010 00001101 00001010 01001001 00100000 01101011 01101110 01101111 01110111 00100000 01101010 01100001 01100011 01101011 00100000 01110011 01101000 01101001 01110100 00100000 01100001 01100010 01101111 01110101 01110100 00100000 01100010 01101001 01101110 01100001 01110010 01111001 00100001


:lol: :lol: :lol:

Ok, thats enough from me now :)
User avatar
Hazza
Regular Contributor
Regular Contributor
 
Posts: 2383
Joined: Wed Mar 23, 2005 6:24 pm
Location: Larnaka.. Rating: Very Sexy

Postby Pyrpolizer » Mon Oct 29, 2007 10:43 pm

Hey GR I think the guy wants you to write him the whole program of dividing by twos... :wink:

Just a question though. How can someone tell if a given binary contains the MSB or not?
I mean without knowing this in advance one would think like that
111010=+58
0111010=+58
1111010=+122 not -58
User avatar
Pyrpolizer
Leading Contributor
Leading Contributor
 
Posts: 12893
Joined: Wed Mar 29, 2006 11:33 pm

Postby Pyrpolizer » Mon Oct 29, 2007 10:53 pm

Shit until I typed my message the program is already there!!
Anyone can answer my question though?
User avatar
Pyrpolizer
Leading Contributor
Leading Contributor
 
Posts: 12893
Joined: Wed Mar 29, 2006 11:33 pm

Next

Return to General Chat

Who is online

Users browsing this forum: No registered users and 1 guest