The Best Cyprus Community

Skip to content


How can I Convert negative decimal to binary

Feel free to talk about anything that you want.

Postby Get Real! » Mon Oct 29, 2007 11:09 pm

Pyrpolizer wrote: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


You've only used up 7 bits Pyro, you forgot one bit! :)

I started off the theory for Acunga with the simplest 8-bit system that works for numbers between -128..127.

Here's a handy table to clear things up...

Name.................. Size.........Range
Byte.....................8-bit.......-128..127
Word....................16-bit......-32768..32767
Double Word.........32-bit......-2147483648..2147483647

Regards, GR.

In case you didn't understand...

10111010 -58
01111010 122
Last edited by Get Real! on Mon Oct 29, 2007 11:15 pm, edited 1 time in total.
User avatar
Get Real!
Forum Addict
Forum Addict
 
Posts: 48333
Joined: Mon Feb 26, 2007 12:25 am
Location: Nicosia

Postby phoenix » Mon Oct 29, 2007 11:14 pm

:D
User avatar
phoenix
Main Contributor
Main Contributor
 
Posts: 3452
Joined: Wed Aug 22, 2007 2:47 pm
Location: Free From Forum

Postby Get Real! » Mon Oct 29, 2007 11:17 pm

phoenix wrote::D

You like, you like? :lol:
User avatar
Get Real!
Forum Addict
Forum Addict
 
Posts: 48333
Joined: Mon Feb 26, 2007 12:25 am
Location: Nicosia

Postby phoenix » Mon Oct 29, 2007 11:21 pm

Get Real! wrote:
phoenix wrote::D

You like, you like? :lol:


Thank you! . . . . please continue :D
User avatar
phoenix
Main Contributor
Main Contributor
 
Posts: 3452
Joined: Wed Aug 22, 2007 2:47 pm
Location: Free From Forum

Postby Get Real! » Mon Oct 29, 2007 11:23 pm

:D Those interested can have a play with number systems in Windows right here…

Start > All Programs > Accessories > Calculator

And then just go… View > Scientific

Now you can perform functions in… Decimal (Base 10), Octal (Base 8 ), Hexadecimal (Base 16), and Binary (Base 2) !

Regards, GR.


NB: Forgot to mention... Windows XP only! :lol: I wouldn't have a clue where the calculator is in Vista!
User avatar
Get Real!
Forum Addict
Forum Addict
 
Posts: 48333
Joined: Mon Feb 26, 2007 12:25 am
Location: Nicosia

Postby phoenix » Mon Oct 29, 2007 11:53 pm

Hhhmmm :? Definitely something missing . . . :(
User avatar
phoenix
Main Contributor
Main Contributor
 
Posts: 3452
Joined: Wed Aug 22, 2007 2:47 pm
Location: Free From Forum

Postby boomerang » Tue Oct 30, 2007 12:18 am

User avatar
boomerang
Main Contributor
Main Contributor
 
Posts: 7337
Joined: Sat May 14, 2005 5:56 am

Postby phoenix » Tue Oct 30, 2007 12:31 am



Thanks Boom! :D

The first one won't open . . . but I'll have a play with the second (if those pop-ups stop interfering) :D

How are you with Fermat's Last theorem? . . . and BTW have you read "The Music of the Primes" by Marcus du Sautoy ?
User avatar
phoenix
Main Contributor
Main Contributor
 
Posts: 3452
Joined: Wed Aug 22, 2007 2:47 pm
Location: Free From Forum

Postby Pyrpolizer » Tue Oct 30, 2007 12:49 am

GR I was expecting an answer along the lines that computers use additional "tricks" to the pure mathematical value of binary numbers. After all binary numbers are only used by computers, so it's their problem.

So unless you trick the scientific calculator of windows by deleting the leftmost digit you will never get it to give you 10111010=-58. It will always give you +186. The reason is, the windows calculator works purely mathematically, and doesn’t care if you use 8 bit or 16 bit or 32 bits.
True or not?
User avatar
Pyrpolizer
Leading Contributor
Leading Contributor
 
Posts: 12893
Joined: Wed Mar 29, 2006 11:33 pm

Postby Get Real! » Tue Oct 30, 2007 1:26 am

Pyrpolizer wrote:GR I was expecting an answer along the lines that computers use additional "tricks" to the pure mathematical value of binary numbers. After all binary numbers are only used by computers, so it's their problem.

So unless you trick the scientific calculator of windows by deleting the leftmost digit you will never get it to give you 10111010=-58. It will always give you +186. The reason is, the windows calculator works purely mathematically, and doesn’t care if you use 8 bit or 16 bit or 32 bits.
True or not?

Pyro, the Windows calculator is just another computer program that SIMULATES a calculator so the onus was on the programmer who wrote it how to deal with negative number conversions and unfortunately he did… NOTHING! All he had to do to fix the problem is this… (pseudo code follows…)

The variable “Number” used below represents the number to be converted from Decimal to Binary…


IF (Number<0) THEN <-- This is the CONDITION required to filter negatives
BEGIN
(All negatives come in here so you can SET bit 1 in answer)

END ELSE
BEGIN
(All positives come in here so DO NOT change bit 1 in answer)

END.


Had the Windows calculator displayed an “error” when trying to convert a negative decimal number to Oct, Bin, or Hex, then I would’ve given the programmer some credit for at least DETECTING such a likely scenario but instead it displays GARBAGE!

This clearly falls under the description of a “BUG” and should be reported to Microsoft.

Given that this calculator calls itself “scientific” then you’d think that it would handle negatives more gracefully.

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

PreviousNext

Return to General Chat

Who is online

Users browsing this forum: No registered users and 1 guest