• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

how 2 get binary number for -ve numbers

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am confused !!
can some one give an example like how to find the binary number for negative numbers.
i know this tech. to get the binary number for -ve values.Please correct me b'coz for some numbers i am getting diff. values.
lets take -192
step1:
we should take 192 and minus 1 i,e 191
step2:
get the binary form for 191 i,e 10111111
step3:and then change 0's to 1 and 1's to 0's
i,e 01000000(which is the binary value of -192)
am i going in the right way?please let me know.
[ January 29, 2002: Message edited by: kittu anu ]
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by kittu anu:
Hi all,
I am confused !!
can some one give an example like how to find the binary number for negative numbers.
i know this tech. to get the binary number for -ve values.Please correct me b'coz for some numbers i am getting diff. values.
lets take -192
step1:
we should take 192 and minus 1 i,e 191
step2:
get the binary form for 191 i,e 10111111
step3:and then change 0's to 1 and 1's to 0's
i,e 01000000(which is the binary value of -192)
I am going in the right way.please let me know.


Well, how about we go from negative to positive and then back! Let's take an easy number to work with: -1. The binary representation for -1 is simple (I'll use just eight bits instead of the 32 in an int): 11111111. Now, to get the positive version, we flip all the bits, so our binary number is now 00000000. Then, we add 1, so we get 00000001. In decimal, this is a positive 1.
Now, to take a positive to a negative, we just reverse the process - so subtract 1 from our binary 00000001 and we get 00000000, then flip the bits and we get 11111111, which is the binary representation of -1 in decimal. Just repeat the process for any number.
Easy, isn't it! The best way to check your work is to use a calculator that works in binary and decimal - I always use the calculator that comes with Windows and turn on the scientific view to use the different bases.
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see this link
 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at this dicussion and see if it is of any help -
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=33&t=003578
HTH,
- Manish
 
kittu anu
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everyone!! This is just what I needed.
 
A timing clock, fuse wire, high explosives and a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic