CompSci fag needs help

CompSci fag needs help.
Trying to convert decimal to binary without the function, but odds always show up as 11111111 and evens as 00000000

selfbumping

bumping bc I'm about to solve this for you but I need a few more seconds to look at it

you need to divide num by 2 after each iteration though the loop
you're just taking the modulus of the same number 8 times, which gives you either 8 zeroes or 8 ones

this

This. Just google it if you aren't intelligent enough to figure it out on your own.

Thanks user

this. Modular divide by the way. Or divide and floor. also #sqt

set the variable inside the loop so that it will become recursive

just switch majors now holy shit

as a professional software engineer, i cringe every time i see people use strings like this
strings are immutable, so each time you add two strings like that, you're generating more garbage that needs to be collected
use a StringBuffer or something

As a programming hobbyist, when is recursion considered a good thing? Don't excessive function calls slow things down? It's also weird to me that they seem to teach it so early. It's so much easier to use loops.

Iterate you dumb fuck.....

In the getBinary method, put j++; somewhere. How is the value suppoed to change if you dont iterate it?

hardly ever
recursion doesn't work well for solving large problems because of limited stack space
recursion is mostly used for first year compsci homework

for (int i = 0; i < sizeof(int) * 8; i++)
output.Append((num >> i) & 0x01);

it is iterated

So why the hell don't they save it for upper level courses where you have the competence to know when it's useful? I've seen recursive examples for fibonacci-like stuff and can barely wrap my head around it, while looping is totally straightforward. It seems like two totally different ways of thinking. So the useful one should be taught first, right?

This probably wouldve been better suited for work safe requests

i honestly don't know
recursion is useful in some circumstances, but in most cases it's more efficient to implement the same algorithm without recursion
maybe they teach it early because it's somewhat difficult to grasp, so they can weed out people who aren't cut out for programming?

if op uses bitwise operators, his teacher will know he cheated

obviously not. op's problem has already been solved several times in under half an hour. request boards are slow as fuck

>so they can weed out people who aren't cut out for programming
makes sense. Guess that's why I just fuck around on challenge sites.

This. OP confirmed CS newfag.

OP, of course it does that. That's exactly what you told it to do lol.

Try this:

private static void printBinaryform(int number) {
int remainder;

if (number > 1);
System.out.print(remainder);
}

Check for negative and/or non-whole numbers before calling this method.

Thanks, Google and Stack Overflow

This is why a cs degree don't mean shit compared to 3 months work experience op. Not saying I won't hire them but I'd rather hire an auto mechanic that wants to change careers.

congratulations, you took an incredibly simple algorithm and made it more complicated and less efficient by using recursion

Yeah. Off the top of my head fib must be big o "holy fuck" and a simple loop would be linear.

Yeah, people straight out of school are fucking retarded. I only have 4 years experience but I'm about 86000 times better than when I graduated. I can't really see me getting better though. I imagine I'll be better in a decade, but I can't imagine how because I feel like there's little room for improvement.

if you cache the results for each fib call, you can get close to 10% of the performance of a linear solution, and still have all the street cred from using recursion

once you've mastered the basics, expand into software architecture
any code monkey can write basic self-contained systems, but designing large systems and leading teams of engineers to build them is a much different skillset

I haven't done anything too big, but I built a server from scratch that's pretty decent over the last several months. The client side is done by a few very lowly paid India devs who I manage. They are just a little better than OP. We have two customers for over a million dollars right now, and hopefully more customers coming.

I'd love to work for myself. The company is making a lot of cash off of very little dev investment. The server is 90% of the project and I did it by myself but the company makes almost all of the money.

>Don't excessive function calls slow things down?
It's usually negligible. I only worry about it on code for embedded microcontrollers, but even then I'm more worried about stack space than execution time.

And if the environment/compiler supports tail call elimination it can mean the calls in your recursion don't push a new frame eliminating both the time and memory considerations of a call.

>It's also weird to me that they seem to teach it so early. It's so much easier to use loops.
It's mostly useful as a tool to get dummies comfortable with functions as a way to break their code into reusable utilities along reasonable boundaries, not just a way to turn 1, 100-line function into 4, 25 line functions.

An intro to programming course using Java doesn't teach recursion because the professor secretly wants the students to become functional programming weenies. The teacher wants to force a student to stretch their mind around the fact fib(x) will be called by two very different types of caller.

recursion. read the book negro

read(book)
{
if(book.empty())
{
celebrate()
return
}
first = book.firstCharacter()
rest = book.removeFirstCharacter()
lookAtCharacter(first)
read(rest)
}

>recursion is usually negligible.
My only experience is in R. It's famously slow even among other interpreted languages, and recursion is definitely not negligible there. In fact the recursion depth is set by default to 5000, so fib(5001) would just return an error.

>It's mostly useful as a tool to get dummies comfortable with functions as a way to break their code into reusable utilities along reasonable boundaries
>The teacher wants to force a student to stretch their mind around the fact fib(x) will be called by two very different types of caller.
That makes sense. Although,
a) Normal loops can also be broken in to nice, modular, editable chunks, right?
b) If you don't understand there's more than one style/algorithm that can accomplish something, you're not even interested in programming at all.

there are built in functions but to do it your way

while(num > 0)
binarystring = base10Int % 2 + binarystring
base10Int = base10Int / 2
end loop
return binarystring

Oops typo'd y loop condition:

while(base10Int > 0)
binarystring = base10Int % 2 + binarystring
base10Int = base10Int / 2
end loop
return binarystring

I dont feel like getting deap into this but bascially your probelm is that you're not chaing num as you loop through it