• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

Silly question on binary conversion!

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know this is a silly question. However, I forgot how to convert a negative decimal to a binary. If there any web site on this topic, thanks!
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here goes:
take the positive counterpart of your negative number, then convert it to binary. Finally inverts all bits (0 to 1 and 1 to 0) and add 1.
Example:
Negative number: -145
Positive number: 145
Binary of 145: 00000000 00000000 00000000 10010001
invert all bits: 11111111 11111111 11111111 01101110
add 1: 11111111 11111111 11111111 01101111
the last binary sequence is actually the binary representation of -145
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
[This message has been edited by Valentin Crettaz (edited December 18, 2001).]
 
Ranch Hand
Posts: 1246
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is not really!!! I studied it and forgot about it and stuy it again!! forgot it again!! and .. etc etc.
take a look at this link... http://www.janeg.ca/scjp/oper/binhex.html
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Fei,
So, what is wrong with the above conversion method.
Bala.
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hey Bala:
Nothing wrong....just that FEI forgot again.....
sorry couldn't resist....

- satya
 
Vinny Chun
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Valentin. Your explanation is simple and clear!
 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at this discussion and see if it is of some help -
http://www.javaranch.com/ubb/Forum33/HTML/003578.html
HTH,
- Manish
[Edited by Val: the link was not a hyperlink ]
[This message has been edited by Valentin Crettaz (edited December 19, 2001).]
 
Yeah, but how did the squirrel get in there? Was it because of the tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic