• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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: 9046
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.
 
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic