• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

New C homework. really confused

Danimal1209

Senior member
My objective here is to write functions that perform bitwise binary and unary operations. I just need to get an idea of how I can perform these, I really have no idea.

For example, I need to write a bitwise OR of x and y. I know in code it would be set like this:

int randomVar = x | y

But, I cannot do this. I'm not allowed to use the | operator. I'm only allowed to use the NOT(~) and AND(&) operators. And I cannot use any kind of loop either. I'm really confused with this.

Any help? I would really not prefer an actual answer, but more of a prod in the right direction.
 
Think about it like a hardware problem. You want an OR gate, but you only have AND and NOT gates. How can you wire them to make something that behaves like an OR gate?

I think the fact that you're doing this in software is making it more complicated than it should be. You don't need loops, functions, etc. Just think about gates.
 
Think about it like a hardware problem. You want an OR gate, but you only have AND and NOT gates. How can you wire them to make something that behaves like an OR gate?

I think the fact that you're doing this in software is making it more complicated than it should be. You don't need loops, functions, etc. Just think about gates.

might be equally confusing if they havent taken an introductory hardware course
 
I figured it out. I think it was to not both variables, then AND them.

I had a whole different thought process going on in my head. I was totally over thinking it.

Thanks guys! I'll probably have more C questions later lol.
 
I think this question actually raises a fundamental issue more than anything else. I have seen more and more schools simply not having/requiring boolean logic courses anymore. Even my school did not require it (at least for computer science majors).

I had it because I started as an Electrical and Computer Engineer and then changed majors to Computer Science. And while so many of my classmates were struggling in a few of the classes my friend (who also changed majors at the same time) and I found the concepts very easy because we had taken a logic course.
 
I think this question actually raises a fundamental issue more than anything else. I have seen more and more schools simply not having/requiring boolean logic courses anymore. Even my school did not require it (at least for computer science majors).

I had it because I started as an Electrical and Computer Engineer and then changed majors to Computer Science. And while so many of my classmates were struggling in a few of the classes my friend (who also changed majors at the same time) and I found the concepts very easy because we had taken a logic course.

I double majored in CS and EE, so I got to see both sides of it.

As part of the CS curriculum, the CS students had to take the EE digital logic design class. It was practically a blow off class for the EE students, but the CS students really struggled with it.

On the other hand, the EE students had to take a simple programming course (basically covering the first few weeks of an intro to CS course) and they really struggled with it.

There must be some sort of mindset difference between the two majors.
 
I double majored in CS and EE, so I got to see both sides of it.

As part of the CS curriculum, the CS students had to take the EE digital logic design class. It was practically a blow off class for the EE students, but the CS students really struggled with it.

On the other hand, the EE students had to take a simple programming course (basically covering the first few weeks of an intro to CS course) and they really struggled with it.

There must be some sort of mindset difference between the two majors.

There was some type difference when I went to school (in the dark ages) there was no CS department. Computers were almost non existent - think slide rules.

I was an EE and struggled badly in electronics courses. Programming courses; compiles, languages, applications were a piece of cake. My best man was the reverse. He could work with circuits in his sleep; but for the life of him, not be able to analyze a problem and break it apart into components.
 
I find minecraft is a neat way to teach people logic. My wife is taking a intro programming course and I used minecraft to help her get the basics of logic gates.
 
There was some type difference when I went to school (in the dark ages) there was no CS department. Computers were almost non existent - think slide rules.

I was an EE and struggled badly in electronics courses. Programming courses; compiles, languages, applications were a piece of cake. My best man was the reverse. He could work with circuits in his sleep; but for the life of him, not be able to analyze a problem and break it apart into components.

I found analog electronics to be really difficult and I hated the math. I'm pretty good at software and digital electronics, which require the same logic mindset.
 
int randomVar = ~x & y

NOT x and Y, is the the answer you got OP?

I dont know C im currently learning java but i remember the boolean algebra module a few months back being a real pita 😵
 
Back
Top