• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

converting decimals to binary

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone suggest a good resource of how I can re-learn converting decimals to binary:
0001 = 1
0010 = 2
0011 = 3
0100 = 4
But this:
11000000 = -64
Could someone point me in the right direction?
TIA
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not know why do you call them decimal as these are all integers but anyways.
Binary is base 2 and you have signed and unsigned data types.
any java book will have nice explanation
 
Paul Salerno
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tarik For The Correction.
Actually I have the RHE book and there IS NO good explanation of this
Can someone who wants to help me, please give me a good suggestion.
Thanks again
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
 
Paul Salerno
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Valentin,
I wasnt sure exactly what to search for, but I appreciate the links.
-Paul
 
Paul Salerno
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I replied with a question on this which got flipped on the beginners forum.
Has to do with the most significant bit, one person takes it into account, another doesnt.
Could one of you smart guys take a stab at it?
Thanks!
 
Valentin Crettaz
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
done...
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=33&t=004642
HIH
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is what I found as the easiest way:
Simple conversion between decimal and binary.
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried it here:
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=33&t=004642
And for tarik:

I do not know why do you call them decimal as these are all integers but anyways.


64 (e.g.) is just a number written in a decimal way which has (at this point) nothing to do with integers..
Erik Dark
 
Paul Salerno
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you all very much for your enormous amount of help
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,
Assumming the bit pattern is a byte and not the lower bit pattern end of an integer then the decimal value is -64.
The bit range of a byte is 2^-7 to 2^7-1 so half of the bit patterns represent negative numbers. The negative values are identified by the first bit starting with 1. To do a binary/Denary conversion:
Subtract the bit pattern from 0.
00000000
- 11000000
--------
Bring the left operand to compliments 2
by flipping the bits and adding 1
00111111
1
--------
01000000
Now add this to the first operand:
00000000
+ 01000000
--------
01000000
the result represents a value of 64
and sign it: -64
Now try it for an integer as an exercise:
say: FFFFFDEA
Convert it to a denary.
Regards
Stephen


 
mooooooo ..... 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