Click here to Skip to main content
15,885,435 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Precompiled Headers Pin
Chris Losinger24-Jun-12 12:35
professionalChris Losinger24-Jun-12 12:35 
AnswerRe: Precompiled Headers Pin
jschell25-Jun-12 9:45
jschell25-Jun-12 9:45 
QuestionPut text data to position where cursor is blinking Pin
khanhnd14058224-Jun-12 4:34
khanhnd14058224-Jun-12 4:34 
QuestionWin32 local aplication using accessing mysql instaled in a site with easyphp ... Pin
SNArruda23-Jun-12 13:02
SNArruda23-Jun-12 13:02 
AnswerRe: Win32 local aplication using accessing mysql instaled in a site with easyphp ... Pin
markkuk23-Jun-12 23:43
markkuk23-Jun-12 23:43 
QuestionBinary value Division Pin
Syed umair shah23-Jun-12 0:48
Syed umair shah23-Jun-12 0:48 
AnswerRe: Binary value Division Pin
Richard MacCutchan23-Jun-12 2:14
mveRichard MacCutchan23-Jun-12 2:14 
AnswerRe: Binary value Division Pin
Software_Developer23-Jun-12 11:20
Software_Developer23-Jun-12 11:20 
C#
#include <stdio.h>
#include <stdlib.h>

void load(int*, int*, int*);
void display(int*, int*, int*);
void compute(int*, int*, int*);
void adder(int*, int*);
void negate(int*);

void main()
{
    int i;
    int DIVISOR [5];
    int REMAINDER [5];
    int DIV_QUOT [4];   // DIVIDEND - QUOTIENT

//initialising registers with data
    load(DIVISOR, REMAINDER, DIV_QUOT);

    //Decorations.
    printf("  DIVISOR |\t     REMAINDER\t     DIVIDEND/QUOTIENT");
        printf("\n  --------|----------------");
            printf("---------------------------\n");

    display(DIVISOR, REMAINDER, DIV_QUOT);  //general display
        printf("\n  --------|----------------");
            printf("---------------------------\n");
    //Done with decorations.

    //computation
    for (i=0; i<4; i++)
    {
        compute(DIVISOR, REMAINDER, DIV_QUOT);  //compute 1st bit
        printf("\n  --------|----------------");
            printf("---------------------------\n");
    }
}





///////////////////////////////////////////////////////
// Computation
void compute(int DIVISOR[], int REMAINDER[], int DIV_QUOT[])
{
    int DIVISOR_Copy [5];
    bool neg;

    REMAINDER[1] = REMAINDER[2];
    REMAINDER[2] = REMAINDER[3];
    REMAINDER[3] = REMAINDER[4];
    REMAINDER[4] = DIV_QUOT[0];
    DIV_QUOT[0] = DIV_QUOT[1];
    DIV_QUOT[1] = DIV_QUOT[2];
    DIV_QUOT[2] = DIV_QUOT[3];
    DIV_QUOT[3] = 888;          //flag to put "?" sign

    display(DIVISOR, REMAINDER, DIV_QUOT);  //display
    printf("  |  <--- Shifting left...\n");


    // NOW LETS DETERMINE THE STATUS OF DIV_QUOT[3]
    // TO DO SO.... SUBSTRACT. (REMAINDER - DIVISOR) AND SEE
    // IF NEGATIVE, IT IS 0; AND RESTORE REMAINDER
    // IF POSITIVE IT IS 1 AND DO NOT RESTORE REMAINDER.

    /////////////////////////
    // SUBSTRACT operation HERE.
    // REMAINDER - DIVISOR  = ?
    //
    // first lets create and negate DIVISOR_Copy
    // an image of DIVISOR

    DIVISOR_Copy[0] = DIVISOR[0];
    DIVISOR_Copy[1] = DIVISOR[1];
    DIVISOR_Copy[2] = DIVISOR[2];
    DIVISOR_Copy[3] = DIVISOR[3];
    DIVISOR_Copy[4] = DIVISOR[4];

    negate(DIVISOR_Copy);

    adder(REMAINDER, DIVISOR_Copy);     // Addition (actually substraction)

    if (REMAINDER[0] == 1)          // Checking control bit.
                            // (overflow or neg)
        neg = 1;  /// Negative
    else
        neg = 0;  /// Positive

    display(DIVISOR, REMAINDER, DIV_QUOT);  //display

    if (neg)    // if the number was negative,
            // restore REMAINDER and assign 0 to D[3]
    {
        adder(REMAINDER, DIVISOR);  //Restoration
        DIV_QUOT[3] = 0;
        printf("  |  NEGATIVE. ? = 0\n");
    }
    else
    {
        DIV_QUOT[3] = 1;
        printf("  |  POSITIVE. ? = 1\n");
    }
    display(DIVISOR, REMAINDER, DIV_QUOT);  //display
}


///////////////////////////////////////////////////////
// Two's compliment.
void negate(int A[])
{
    int i;
    int ONE[5];
    ONE[0] = 0;
    ONE[1] = 0;
    ONE[2] = 0;
    ONE[3] = 0;
    ONE[4] = 1;

    for (i=0; i<=4; i++)
    {
        if(A[i] == 1)
            A[i] = 0;
        else
            A[i] = 1;
    }
    //ADD 1
    adder(A, ONE);
}


///////////////////////////////////////////////////////
// 4 bit adder.
void adder(int A[], int B[])
{
    int next, i, carry=0;

    for (i=4; i>=0; i--)    // 4, because we have sign control bit
    {
        next = 1;
        if (A[i]==0 && B[i]==0)     //00 case
        {
            A[i]= carry;
            carry = 0;
            next = 0;
        } // good.

        if (next)
        if (A[i]==0 && B[i]==1)     //01 case   - transfer
        {
            if (carry == 0)
                A[i] =1;
            else
                A[i]=0;
            next = 0;
        }

        if(next)
        if (A[i]==1 && B[i]==0)     //10 case   - transfer
        {
            if (carry == 0)
                A[i] =1;
            else
                A[i]=0;
            next = 0;
        }

        if(next)
        if (A[i]==1 && B[i]==1)     //11 case - generate
        {
            if (carry == 0)
            {
                A[i] =0;
                carry = 1;
            }
            else
                A[i]=1;
        next = 0;
        }
    }
}



///////////////////////////////////////////////////////
//displaying {OK}
void display(int A[], int B[], int C[])
{
    int i;
    printf(" ");
    for(i=1; i<=4; i++)
        printf(" %d", A[i]);
    printf(" |          ");

    for(i=1; i<=4; i++)
        printf(" %d", B[i]);
    printf("            ");

    for(i=0; i<=3; i++)
        if ((C[i] == 0) || (C[i] == 1))
            printf(" %d", C[i]);
        else
            printf(" ?");
}

///////////////////////////////////////////////////////
//function to load registers with data.  {OK}
void load(int A[], int B[], int C[])
{

    A[0] = 0;
    A[1] = 1;  //DIVISOR
    A[2] = 0;
    A[3] = 0;
    A[4] = 0;

    B[0] = 0;  // !!!!!!SIGN CONTROL BIT!!!!!!
    B[1] = 0;  // ALL ZEROS
    B[2] = 0;  // ALL ZEROS
    B[3] = 0;  // ALL ZEROS
    B[4] = 0;  // ALL ZEROS


    C[0] = 1;  //DIVIDEND / QUOT
    C[1] = 0;
    C[2] = 0;
    C[3] = 0;
}

Questionhow to do logic gates Pin
Syed umair shah23-Jun-12 0:47
Syed umair shah23-Jun-12 0:47 
AnswerRe: how to do logic gates Pin
Brandon-X1200023-Jun-12 13:11
Brandon-X1200023-Jun-12 13:11 
Questionhow to do logiz gates Pin
Syed umair shah23-Jun-12 0:45
Syed umair shah23-Jun-12 0:45 
AnswerRe: how to do logiz gates Pin
Software_Developer23-Jun-12 11:07
Software_Developer23-Jun-12 11:07 
QuestionWhat FTP pack can obtain the detail events? Pin
includeh1022-Jun-12 22:36
includeh1022-Jun-12 22:36 
AnswerRe: What FTP pack can obtain the detail events? Pin
Jochen Arndt22-Jun-12 23:03
professionalJochen Arndt22-Jun-12 23:03 
QuestionOnly unist.isu gets installed by visual C++ install shield Pin
adityarao3122-Jun-12 20:30
adityarao3122-Jun-12 20:30 
QuestionMFC UI Thread vs. Background Thread Pin
Richard Andrew x6422-Jun-12 10:19
professionalRichard Andrew x6422-Jun-12 10:19 
AnswerRe: MFC UI Thread vs. Background Thread Pin
«_Superman_»22-Jun-12 17:19
professional«_Superman_»22-Jun-12 17:19 
SuggestionRe: MFC UI Thread vs. Background Thread Pin
Roger Stoltz23-Jun-12 0:26
Roger Stoltz23-Jun-12 0:26 
GeneralRe: MFC UI Thread vs. Background Thread Pin
Richard Andrew x6423-Jun-12 8:31
professionalRichard Andrew x6423-Jun-12 8:31 
AnswerRe: MFC UI Thread vs. Background Thread Pin
Vitaly Tomilov23-Jun-12 13:17
Vitaly Tomilov23-Jun-12 13:17 
AnswerRe: MFC UI Thread vs. Background Thread Pin
fat_boy23-Jun-12 23:55
fat_boy23-Jun-12 23:55 
QuestionA Simple C++ Question. Pin
Sivaraman Dhamodharan22-Jun-12 4:19
Sivaraman Dhamodharan22-Jun-12 4:19 
AnswerRe: A Simple C++ Question. Pin
David Crow22-Jun-12 4:47
David Crow22-Jun-12 4:47 
GeneralRe: A Simple C++ Question. Pin
Sivaraman Dhamodharan26-Jun-12 0:51
Sivaraman Dhamodharan26-Jun-12 0:51 
AnswerRe: A Simple C++ Question. Pin
Albert Holguin22-Jun-12 5:05
professionalAlbert Holguin22-Jun-12 5:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.