• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

k&b page no. 231

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey,
in last example down the page the code is
Long l2= Long.parseLong("101010" , 2);

my question is that does string 101010 reflect 52 in decimal (book shows it to be 42)???


 
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Deepesh,

101010 is 42 in binary:

0 x 2^0 = 0
1 x 2^1 = 1
0 x 2^2 = 0
1 x 2^3 = 8
0 x 2^4 = 0
1 x 2^5 = 32

1 + 8 + 32 = 42


Here's a concise intro to binary if you're unfamiliar with the notation:
http://l3d.cs.colorado.edu/courses/CSCI1200-96/binary.html
[ November 09, 2007: Message edited by: Kelvin Lim ]
 
deepesh mathur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kelvin Lim:
Hi Deepesh,

101010 is 42 in binary:

0 x 2^0 = 0
1 x 2^1 = 1
0 x 2^2 = 0
1 x 2^3 = 8
0 x 2^4 = 0
1 x 2^5 = 32

1 + 8 + 32 = 42


Here's a concise intro to binary if you're unfamiliar with the notation:
http://l3d.cs.colorado.edu/courses/CSCI1200-96/binary.html

[ November 09, 2007: Message edited by: Kelvin Lim ]






IS THIS REALLY EQUAL TO 42
i mean
DON'T YOU HAVE MADE A SILLY CALCULATION MISTAKE???

1 + 8 + 32 = 42
it should be
2 + 8 + 32 = 42
(SORRY IF IT HURTS)
but anyways thanks...
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
be nice Deepesh!
 
deepesh mathur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry bert, kelvin
but really i must admire you are a genius
who is not only encapsulated in a bunch of java code
but is a real warrior...
(and please don't feel bad as i am only a kid in your field
seeking forgiveness )

regards
DEEPESH
[ November 10, 2007: Message edited by: deepesh mathur ]
 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Umm, see, I was just making sure you really read my reply! Yeah, that's it!

Anyway, no worries, Deepesh. No offense taken at all. I'm just glad to be able to help out once in a while.
 
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic