Java function that will convert an arbitrary base to a decimal

D

Daniel

I need to write a Java function that will convert an arbitrary base to
a decimal. The number needs to be converted into an array of
characters. It needs to use uppercase letters of the alphabet for
input if required by the value of base. Needs to have a void function
to convert it to the proper value of type array of int before
converting it to a decimal.

example given by book:

const int base = 6;
const int numDigits = 4;
int number [numDigits];

The program must be modified with a different base by changing only
the constant base, and the number of digits needs to be modified by
changing numDigits.

This is for a computer systems class , and any help will be greatly
appreciated.
 
A

Aeris

Daniel said:
I need to write a Java function that will convert an arbitrary base to
a decimal. The number needs to be converted into an array of
characters. It needs to use uppercase letters of the alphabet for
input if required by the value of base. Needs to have a void function
to convert it to the proper value of type array of int before
converting it to a decimal.

example given by book:

const int base = 6;
const int numDigits = 4;
int number [numDigits];

The program must be modified with a different base by changing only
the constant base, and the number of digits needs to be modified by
changing numDigits.

This is for a computer systems class , and any help will be greatly
appreciated.

This is native in Java:

http://download.oracle.com/javase/6/docs/api/java/lang/Long.html#valueOf(java.lang.String,
int)
http://download.oracle.com/javase/6/docs/api/java/lang/Long.html#toString(long,
int)
 
M

markspace

This is for a computer systems class , and any help will be greatly
appreciated.


Well, the first thing I would encourage you to do is to go to your
instructor and ask him or her, and to go to your computer lab and get
help from one of the student assistants there. If you are having
problems, they need to know about it. Otherwise, that whole "paying for
instruction" thing is kinda money going to waste.

What they will probably say is "Let's see what you've done so far," and
folks here will say the same. Write some code and show it to your
instructor and student assistants. We'll need to see that code too.
What you posted was not Java, nor any language I recognize, so we can't
do anything with it.
 
R

Robert Klemme

I need to write a Java function that will convert an arbitrary base to
a decimal.

Actually you do not want to convert a base but rather a number
representation in a certain base into a representation with another base.
The number needs to be converted into an array of
characters. It needs to use uppercase letters of the alphabet for
input if required by the value of base. Needs to have a void function
to convert it to the proper value of type array of int before
converting it to a decimal.

Why a void function for a conversion?
example given by book:

const int base = 6;
const int numDigits = 4;
int number [numDigits];

This is not Java.
The program must be modified with a different base by changing only
the constant base, and the number of digits needs to be modified by
changing numDigits.

This is for a computer systems class , and any help will be greatly
appreciated.

Erm, what kind of help do you expect? Learning is best achieved by
trying out things until one hits a roadblock. This is the point to ask
for help - not at the beginning. I am sure whoever gave the assignment
has made sure that you got some basic knowledge to solve the task.

Kind regards

robert
 
D

Daniel

I need to write a Java function that will convert an arbitrary base to
a decimal.

Actually you do not want to convert a base but rather a number
representation in a certain base into a representation with another base.
The number needs to be converted into an array of
characters. It needs to use uppercase letters of the alphabet for
input if required by the value of base. Needs to have a void function
to convert it to the proper value of type array of int before
converting it to a decimal.

Why a void function for a conversion?
example given by book:
const int base = 6;
const int numDigits = 4;
int number [numDigits];

This is not Java.
The program must be modified with a different base by changing only
the constant base, and the number of digits needs to be modified by
changing numDigits.
This is for a computer systems class , and any help will be greatly
appreciated.

Erm, what kind of help do you expect?  Learning is best achieved by
trying out things until one hits a roadblock.  This is the point to ask
for help - not at the beginning.  I am sure whoever gave the assignment
has made sure that you got some basic knowledge to solve the task.

Kind regards

        robert

You would think that I would be provided with more info, but this
teacher loves to play games. I have basic Java knowledge but time is
a major factor. I really thought this was a routine problem and
someone had already completed the algorithm. There are literally
millions of algorithms available online and I was hoping to find one
that needed minor modifications.

Anyway thank you for your response.
 
M

Martin Gregorie

That is the problem. It is extra credit and no help will be given. It
is for a computer architecture / computer systems class. I will work on
the code, but I thought somebody might have already completed the
function and would recognize the problem.
I've never done a direct conversion from a string in one base to a string
in another: that way lies madness. However, conversion from to and from a
string in a particular base representation is rather trivial.
 
M

markspace

but I thought somebody might have already completed
the function and would recognize the problem.


Yes, well, that is what I thought. Of course we recognize the
algorithm. That's because we were dilegent in our course work and
didn't copy someone else's work. Do the work yourself if you want to learn.

BTW, what grade level and major is this? I'm just curious.
 
M

markspace

markspace you need to bite me. Be the last time I ask a question in this group.


Oh no! I'm so scared.

Seriously, did you expect any different response? Would you expect a
different response from, say, your instructor if he or she found out
you'd copied your work from the internet?

I don't know the academic policies of your school, but in most colleges
cheating is grounds for expulsion. Not loosing points for your
assignment, not an F in the course. Expulsion.

You and your attitude need a serious reality check. I'm helping you out
by not giving you the answer. And the internet is everywhere, it'd be
easy for your instructor to check for people asking about his or her
assignment online. Google knows all. Something else to think about.
 
A

Arne Vajhøj

Well, the first thing I would encourage you to do is to go to your
instructor and ask him or her, and to go to your computer lab and get
help from one of the student assistants there. If you are having
problems, they need to know about it. Otherwise, that whole "paying for
instruction" thing is kinda money going to waste.

What they will probably say is "Let's see what you've done so far," and
folks here will say the same. Write some code and show it to your
instructor and student assistants. We'll need to see that code too. What
you posted was not Java, nor any language I recognize, so we can't do
anything with it.

It could be C, C++ or C# - they all have const keyword.

Arne
 
A

Arne Vajhøj

You would think that I would be provided with more info, but this
teacher loves to play games. I have basic Java knowledge but time is
a major factor. I really thought this was a routine problem and
someone had already completed the algorithm. There are literally
millions of algorithms available online and I was hoping to find one
that needed minor modifications.

The problem is so basic that it may have been considered
irrelevant to include in an algorithm collection.

There must be 10 millions programmers that can implement it.
But as explained elsewhere in the thread then there is builtin
functions for it in Java.

Arne
 
J

Joshua Cranmer

I don't know the academic policies of your school, but in most colleges
cheating is grounds for expulsion. Not loosing points for your
assignment, not an F in the course. Expulsion.

In theory. In practice, the amount of evidence and time needed to handle
cheating cases means that cheating mostly results in a 0 on the
assignment, unless it's clearly happening multiple times or it's
particularly egregious.

On a related note, if you do have the balls to copy code, at least make
sure the code actually solves the assignment. Probably over half of the
cheaters I've caught would not have gotten a passing grade on the
assignment had I not caught them.
 
M

markspace

It could be C, C++ or C# - they all have const keyword.


The snippet was pretty small, but yes, I guess C or C++ should have been
obvious. Still, it was really weird, at least to me.

Why use an array of ints ("number") to hold the digits? You can only
hold 36 values if you restrict your input to capital letters, as the OP
stated. The whole thing just oozes sloppiness. Whose fault that is, I
don't truly know.
 
R

Roedy Green

R

Robert Klemme

You would think that I would be provided with more info, but this
teacher loves to play games.

What you consider "playing games" might be observed by others as
"giving challenging tasks".
 I have basic Java knowledge but time is
a major factor.

I would guess that with "basic Java knowledge" you should be able to
solve this within a day.
 I really thought this was a routine problem and
someone had already completed the algorithm.  There are literally
millions of algorithms available online and I was hoping to find one
that needed minor modifications.

Frankly, you seem to have a questionable approach to "learning". You
will learn how to program by doing it - not by finding preprogrammed
solutions. This reminds me of [1] - very interesting read!

Cheers

robert


[1] http://home.uchicago.edu/~aabbott/Papers/futurek.pdf
 
L

Lew

Dan said:
I guess your [sic] against the example code listed there too.
I think most everybody in this group needs to get off of their high horse.

Hey, I thought you were done posting in this forum. I guess that was just
rhetoric, huh? How about you get off your high horse, inviting people to bite
you and all, and stop acting so high and mighty your own self, hm?
All I was asking for is a starting place not the whole code.
Like I said this caught me off guard since it was not a programming class.

And this is supposed to justify your vituperative hostility?

Buh-bye now. Go away.
 
L

Lew

Dan said:
All I was asking for is a starting place not the whole code. Like I said this caught me off guard since it was not a programming class.

But you said,
"This is for a computer systems class , [sic]"

Which one is the lie?
 
M

markspace

> It is a computer architecture class.

Just FYI, my computer architecture class involved quite a bit of
programming.

We are
using the A+ book and a computer systems book.


Ooooooh. This explains a lot. You mean like this course description here:

The computer systems
book covers things like assembly programming, object code, and binary
conversions and such.


When a computer science course covers these things, it does so in great
detail. The A+ course I linked looks more like a brief overview. Most
folks on this list are professional programmers. We did the ComSci
course. I think you are the first A+ guy to show up here.

> Thank you Patricia.


One request--could you figure out how to actually reply to the person
you are addressing? All your replies have been to your own post. It's
really lousing up the threading.

I do know one of the biggest mistakes I have ever made is seeking
help in this group,


Depends. I betcha you could think of a few others if you tried.

and if I could figure out how to quit receiving
email about new posts I would go away for good.


There's that good ol' A+ certification at work. Web interfaces are sure
hard to operate. Another high quality A+ graduate for ya!

However, it is hard
to ignore the continual insults that I have had to endure as a result
of what I thought was a legitimate request for help.


Heh, we can be a lot more insulting.

Seriously, I accept that your course work probably doesn't need the
rigor of a full com sci degree. I jumped to a conclusion about your
assignment and if you want my appoligy, you have. I'm sorry I took the
tone I did in my initial post. However, we do get a fair number of
folks who are in a com sci course who post here who are basically asking
us to do their assignments. It's kind of a sensitive subject, not the
least because these folks are cheating themselves out of an education.

So, there was some history here that you weren't aware of, and you
jumped right into it. I usually read through the archives of any
group/mailing list I join, just to get a sense of the group at least.
Helps to avoid obvious faux pas.
 
A

Arne Vajhøj

I do know one of the biggest mistakes I have ever made is seeking
help in this group, and if I could figure out how to quit receiving
email about new posts I would go away for good. However, it is hard
to ignore the continual insults that I have had to endure as a result
of what I thought was a legitimate request for help.

You are free to leave.

But it will be your loss. There are good info to get here.

And most other similar places would also be a bit picky about
home work etc..

You may learn something from:
http://catb.org/~esr/faqs/smart-questions.html

Including:
http://catb.org/~esr/faqs/smart-questions.html#homework
http://catb.org/~esr/faqs/smart-questions.html#rtfm
http://catb.org/~esr/faqs/smart-questions.html#keepcool
http://catb.org/~esr/faqs/smart-questions.html#not_losing

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top