• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Dec to Binary Coding Problem

 
Ranch Hand
Posts: 48
Eclipse IDE MySQL Database Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I learned PHP before it was OOP, so I know a bit about coding.  This is my 2nd week of Java programming and I'm up to chapter 10 in "Java: A Beginners Guide, 6th Edition"

I'm trying to write a simple program, but I have errors on lines 21,25, and 32 (so says Eclipse)... What would make this work?



Thanks in advance,
~d
 
Saloon Keeper
Posts: 8220
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you present a problem here pertaining to error messages you are getting, cut and paste those error messages into your post. Be sure to include the part of the messages that says what line the error occurred on.
Line 13: Can't have a method within a method.
Line 14: Don't declare two or more variables at the same time. Put each on its own line.
 
David Cone
Ranch Hand
Posts: 48
Eclipse IDE MySQL Database Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, I tried to fix what you mentioned.



Error: Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method by2bi(byte) is undefined for the type bitPlayer

at bitPlayer/bitPlayer.bitPlayer.main(bitPlayer.java:25)
 
Marshal
Posts: 26596
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't declare a method "Static". The correct term is "static".
 
David Cone
Ranch Hand
Posts: 48
Eclipse IDE MySQL Database Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Screen shot:
 
David Cone
Ranch Hand
Posts: 48
Eclipse IDE MySQL Database Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to both of you... it works now.   *big smile*
 
Paul Clapham
Marshal
Posts: 26596
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some of your code is a bit clumsy though (in my opinion). For example:


I would replace that by this:


 
Marshal
Posts: 3557
505
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens if your input value is larger than 127 (and still 8 bits)?
    short i = 128;
 
Carey Brown
Saloon Keeper
Posts: 8220
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Carey Brown
Saloon Keeper
Posts: 8220
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not practical, but another way to skin the cat.
 
David Cone
Ranch Hand
Posts: 48
Eclipse IDE MySQL Database Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C. Brown....  That's elegant, Thank you.  I haven't learned the format stuff yet.  This is my first program that wasn't homework from the book.  This is only my 2nd week working in Java.... and right now I'm waiting on a new keyboard...  The 'a'  key is broken on this one so every time I use it, I have to Ctrl-v a copy.  Interesting fact about this forum software....  Alt-09 (starting Alt-097) opens up an italics pop-up.  Thanks again.   -d.
 
David Cone
Ranch Hand
Posts: 48
Eclipse IDE MySQL Database Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ron, I haven't tried.... waiting on new keyboard which is due in tomorrow.  Thought range for Short was to 32,767.  I sucessfull wrote a program that wrote a file containing 00 through FF.  Next project is to try loading it in and processing each byte.
 
Carey Brown
Saloon Keeper
Posts: 8220
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Cone wrote:The 'a'  key is broken on this one so every time I use it, I have to Ctrl-v a copy.

If you get sick of doing that you could write your draft in another editor using ~ in place of 'a' and then when you're all done do a global replace before you cut and past the entire thing to The Ranch.
 
Carey Brown
Saloon Keeper
Posts: 8220
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or you could use '@' in place of 'a' and confuse every body. ;)
 
Sheriff
Posts: 16201
270
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you're only doing a byte, you can let String.format do the left-padding for you:

This works because 0b11111111 < Integer.MAX_VALUE and will actually work for up to 10 bits.
 
You showed up just in time for the waffles! And this 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