Fog Creek Software
Discussion Board

Have I got them right?

I'd be obliged if someone could validate the functions I've written below from the try-it-yourself excercises of K&R:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void DWordToWords(const int DWord, short int* LoWord, short int* HiWord);
void MakeDWord(const short LoWord, const short HiWord, int* DWord);
unsigned GetBits(unsigned, int, int);
unsigned SetBits(unsigned, int, int, int);
unsigned Invert(unsigned, int, int);

/*int main(void)
    int DWord;
    short LoWord, HiWord;
    DWord = 1066825727;
    LoWord = HiWord = 0;

    DWordToWords(DWord, &LoWord, &HiWord);
    printf("DWord = %d\nLoWord = %d\nHiWord = %d\n\n", DWord, LoWord, HiWord);

    DWord = 0;
    MakeDWord(LoWord, HiWord, &DWord);
    printf("DWord = %d\nLoWord = %d\nHiWord = %d\n\n", DWord, LoWord, HiWord);

void DWordToWords(const int DWord, short int* LoWord, short int* HiWord)
    *LoWord = DWord & ~(~0<<16);
    *HiWord = DWord>>16;

void MakeDWord(const short LoWord, const short HiWord, int* DWord)
    *DWord = HiWord<<16;
    *DWord |= LoWord;

unsigned int GetBits(unsigned x, int p, int n)
    /*gets the right-adjusted n bits of integer x
    starting from position p*/
    return (x>>(p-n+1)) & ~(~0<<(p-n));

unsigned int SetBits(unsigned x, int p, int n, int y)
    /*set n bits of integer x starting from position
    p to the right-most n bits in integer y*/
    return x|((y&~(~0<<n))<<(p-n+1));

unsigned Invert(unsigned x, int p, int n)
    /*Inverts n bits in x starting from position p*/
    int temp=GetBits(x, p, n);
    return SetBits(x, p, n, temp);

Saturday, June 19, 2004

And this one as well:

unsigned RightRot(unsigned x, int n)
    /*Rotates x rightwards by n bit positions*/
    int temp=GetBits(x, n-1,n);
    return SetBits(x,31,n,temp);

Saturday, June 19, 2004

Dear Sathyaish Chakravarthy:

Did you make Unit tests for these?  That is, did you work them out by hand first using sample numbers and knowledge of the platform and problem domain to come up with the correct answers.

Once again let me pose a question to you:

1. Do you have CS degree?

Why do you seek attention and approval from the people on this forum?  Does your family not give you this?  Does your current work environment not recognize you as you believe you deserve to be recognized? What exactly have you done lately to be recognized?  Is a paycheck not enough?  Do you have the true and false notion that the people on this forum are smarter than you?

My friend Sathyaish, please, please, please cure yourself of this disease.  I recommend getting laid and take some time off.

Saturday, June 19, 2004


A Pterodactylus Ate My Baby
Saturday, June 19, 2004

Dear Anon,

I would much appreciate it, if you clearly probed into yourself and re-stated with more clarity, your case against me. I am truly puzzled by your post.

I hope you are Joel posting in disguise, because if you are not, I would be surprised at your audacity of shooing another poster as yourself for doing exactly what you do.

To answer your questions, I am not a Computer Science Student, and I regret that my parents couldn't afford to pay for my education after my schooling, and neither were they informed enough to offer career guidance.

I visit this forum because I find the collective personality of the body of this forum an indispensible source of knowledge to tap into. This is by no means the only place I post my queries to. I would want you to know, so you may not unsettle your mind in this regard, that I do not consider myself any higher in stature than a student who wishes to learn some of what he could not, one thing of them being the C language.

If I have upset you, I sincerely apologize and humbly I request you not to read my posts, lest I be the cause of your discompeture.

Sathyaish Chakravarthy
Saturday, June 19, 2004

Nice haircut Sathyaish!

Saturday, June 19, 2004

While you're telling him not to read your posts, maybe you ought to think about whether or not this is really an appropriate forum to be posting CompSci 101 questions to.

Saturday, June 19, 2004

One thing for sure: K&R wouldn't like your NamingConventions, Sathyanish.

Sunday, June 20, 2004

Not that I think that you should listen to Anon's remarks but just an FYI: You could signup to the devcpp mailinglist, there a lot of people on it and they know their stuff. Look at the archives to see its something for you signup here:

Sunday, June 20, 2004

It's not that I have anything against you posting to the forum Sathyaish but I do have something against your constant 'nagging'.  How many times have you posted this and still not figured it out?  It seems to me that you seek attention, friends and recognition.  This is normal but you are going about it the wrong way.  You want to seek real life friends not people on some stupid forum.  Don't spend so much time in front of a computer.

You do seem an odd character to me.  Do you work in the software industry?  What kind of software do you actually write over there in India?  If you are a representation of the kind of programmers available in India... well then I think offshoring to India will come to a halt very soon.  One time you made a post about making a program that displayed the 'sine wave' of a sound file.  There are tons of programs that do that.  Are you guys in India writing trivial programs like these just to learn?  If so then your company and your economy is a puff ball and will go poof very soon.  It will crumble before your eyes.

Not having an education is fine, I didn't have a college education either until I was older but I did learn both C and C++ on my own and never posted to forums asking if I was right about certain problems.  I learned C and C++ before any other language.  You have to take the responsibility upon yourself to determine if what you have written is correct.  It is not that difficult to verify.

You may think I am being harsh in my criticizm of you but I'm not.  You may also think that I hate you but I don't.  You may also believe that I do not care about your problems but I do.  This is why I am giving you this advice:

Figure it out on your own.

Sunday, June 20, 2004

"I find the collective personality of the body of this forum an indispensible source of knowledge to tap into"

Except the collective personality of the body of this forum is not interested in teaching you how to program. There are tutorial web sites out there to help you with that.

Tired of this
Sunday, June 20, 2004

*  Recent Topics

*  Fog Creek Home