LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-16-2019, 10:22 AM   #391
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 19.1 MATE
Posts: 7,777
Blog Entries: 3

Rep: Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765

Just in case the very basics of left and right bit shifting as an arithmetic operation haven't quite set in yet:

https://www.youtube.com/watch?v=fDKUq38H2jk
 
2 members found this post helpful.
Old 04-16-2019, 02:26 PM   #392
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 5,061
Blog Entries: 11

Rep: Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007
Quote:
Originally Posted by rtmistler View Post
I'm left thinking, "How did this get broken from a week or so ago when you seemed to understand the fundamental points?"

What exactly is your current question, in ten words or less?
I'll take the blame for breaking the thread in as much as it has resulted from my suggestions to modify my original base conversion program. The intent was to suggest a very simple real-world use for bit shift operations in code already familiar to answer the question asked - "How can I see the numbers in binary?". So let's forget modifying the program.

Quote:
Originally Posted by jsbjsb001 View Post
So I honestly have no idea how to fix it. Maybe I should just move on instead,
But you have already covered everything necessary so why are you so confused by it? That is real question that you should try to answer for yourself.

Don't think in terms of "fixing" anything - we are not debugging! Think exclusively in terms of understanding how and why it works as it does - even why it works incorrectly such as the leading zeros. Put your efforts into understanding why pow2 << x adds a number of leading zeroes proportional to x before trying to "fix" it. Literally ask yourself, "Why does it do that?".

Do not ask yourself "How can I fix this?". Ask yourself, "What does this line of code actually do?", for each and every line in your code, whatever that code may be.

Do not move on before you can answer. Doing so will only lead into another round of, "I honestly have no idea". You really, really need to break that cycle - right now.

Consolidate your knowledge gains at every point and never move on before you can confidently make use of each new bit of knowledge gained - confidently! Otherwise you will have gained nothing at all.

To repeat a point made much earlier in this tread...

Code:
There is absolutely no substitute for understanding what you are doing - none!
That includes "moving on".

Quote:
Originally Posted by rtmistler View Post
I'm sorry, but it seems no matter what I try, I hit yet another roadblock. I can see what the code is doing, but I don't honestly know why it's doing it (even how it correctly figures out the correct binary conversion). I honestly don't know why it's doing the maths it is, other than that's how it figures out the binary number.
The recurring roadblocks are the basic math ideas. Your ability to learn the programming will forever be limited by your inability to deal with the basic math. Simple harsh truth.

At the beginning of this thread there were several posters who stated that basic math knowledge was not necessary to learning programming. I invite those holding that opinion to jump in at this point and remove your roadblocks without the math... [silence?]...

You are a smart person and have shown your ability to understand the various programming concepts (even the math at times) - you can get it. But it also appears to me that you have not actually learned much of it in the sense that you seem unable to reuse it.

What I mean by that is you have clearly understood c-strings, pointers and functions within the examples given, but you seem completely flummoxed by the suggestion of using them. Here is the core problem as expressed by a very smart person...

Quote:
"I can see what the code is doing, but I don't honestly know why it's doing it..."
The missing part is the why, and most of the why is, and will always be, "the math".

Sorry if this seems harsh, I mean it as encouragement, and to again point the way forward. You can and should use the programming knowledge to further the math knowledge, and the math knowledge to further the programming knowledge. But the effort to progress one without the other will ultimately meet with very limited success in my opinion, and each roadblock you hit will be an indicator of those limits.

So I encourage you again to learn the math, as math, then understand the why of programming, as math. Only then will you begin to understand why a left shift multiplies by powers of two, and how to make effective use of it.

With that I'll wish you luck and let the thread get back on track.

Last edited by astrogeek; 04-16-2019 at 03:45 PM.
 
1 members found this post helpful.
Old 04-17-2019, 09:43 AM   #393
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 12,584

Rep: Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929
did you try ddd for example (already)? This is a tool to help understanding your code, a c debugger. Probably you could try it to better understand how the program you wrote works.
 
1 members found this post helpful.
Old 04-18-2019, 01:22 AM   #394
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth? I would say I hope so but I'm not so sure about that... I could just be a figment of your imagination too.
Distribution: CentOS at the time of this writing, but some others over the years too...
Posts: 2,682

Original Poster
Rep: Reputation: 1378Reputation: 1378Reputation: 1378Reputation: 1378Reputation: 1378Reputation: 1378Reputation: 1378Reputation: 1378Reputation: 1378Reputation: 1378
Thanks again guys.

The reason I haven't used a debugger yet was because that hasn't been covered in the chapters I've read so far, and I didn't want to jump the gun so to speak. I think I might leave trying to fix that code for the time being. But thank you for your help all the same pan64.
 
Old 04-18-2019, 02:01 AM   #395
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 12,584

Rep: Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929Reputation: 3929
the reason I suggest you to use ddd is: you can display all the variables you use in your code as you execute it line by line.
I think you will understand what's happening much easier. But obviously it depends on you, if you wish you can try.
 
1 members found this post helpful.
  


Reply

Tags
c programming, learning c


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Finally decided to try to get libinput to work Timothy Miller Linux - Hardware 3 01-04-2018 08:04 PM
Decided to try Lubuntu 14.04 on my netbook... pcninja Ubuntu 4 04-20-2014 08:18 PM
Finally decided to get serious & learn a302svt LinuxQuestions.org Member Intro 1 07-19-2007 12:27 PM
Decided to try Debian some guidance required ninadb Debian 2 08-20-2004 11:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration