Click here to Skip to main content
11,432,427 members (65,378 online)

C / C++ / MFC

 
AnswerRe: Dynamic cast question Pin
fat_boy25-Jun-12 1:45
memberfat_boy25-Jun-12 1:45 
QuestionSetDIBits and GetDIBits (Aarot.zip) Pin
Rabindra Laheri24-Jun-12 19:33
memberRabindra Laheri24-Jun-12 19:33 
AnswerRe: SetDIBits and GetDIBits (Aarot.zip) Pin
Richard Andrew x6424-Jun-12 19:49
memberRichard Andrew x6424-Jun-12 19:49 
GeneralRe: SetDIBits and GetDIBits (Aarot.zip) Pin
Rabindra Laheri24-Jun-12 20:39
memberRabindra Laheri24-Jun-12 20:39 
AnswerRe: SetDIBits and GetDIBits (Aarot.zip) Pin
Richard MacCutchan24-Jun-12 23:22
mvpRichard MacCutchan24-Jun-12 23:22 
QuestionPrecompiled Headers Pin
ForNow24-Jun-12 12:36
memberForNow24-Jun-12 12:36 
AnswerRe: Precompiled Headers Pin
Chris Losinger24-Jun-12 13:35
memberChris Losinger24-Jun-12 13:35 
AnswerRe: Precompiled Headers Pin
jschell25-Jun-12 10:45
memberjschell25-Jun-12 10:45 
QuestionPut text data to position where cursor is blinking Pin
khanhnd14058224-Jun-12 5:34
memberkhanhnd14058224-Jun-12 5:34 
QuestionWin32 local aplication using accessing mysql instaled in a site with easyphp ... Pin
SNArruda23-Jun-12 14:02
memberSNArruda23-Jun-12 14:02 
AnswerRe: Win32 local aplication using accessing mysql instaled in a site with easyphp ... Pin
markkuk24-Jun-12 0:43
membermarkkuk24-Jun-12 0:43 
QuestionBinary value Division Pin
Syed umair shah23-Jun-12 1:48
memberSyed umair shah23-Jun-12 1:48 
AnswerRe: Binary value Division Pin
Richard MacCutchan23-Jun-12 3:14
mvpRichard MacCutchan23-Jun-12 3:14 
AnswerRe: Binary value Division Pin
TopCoder2323-Jun-12 12:20
memberTopCoder2323-Jun-12 12:20 
#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 1:47
memberSyed umair shah23-Jun-12 1:47 
AnswerRe: how to do logic gates Pin
Brandon T. H.23-Jun-12 14:11
memberBrandon T. H.23-Jun-12 14:11 
Questionhow to do logiz gates Pin
Syed umair shah23-Jun-12 1:45
memberSyed umair shah23-Jun-12 1:45 
AnswerRe: how to do logiz gates Pin
TopCoder2323-Jun-12 12:07
memberTopCoder2323-Jun-12 12:07 
QuestionWhat FTP pack can obtain the detail events? Pin
includeh1022-Jun-12 23:36
memberincludeh1022-Jun-12 23:36 
AnswerRe: What FTP pack can obtain the detail events? Pin
Jochen Arndt23-Jun-12 0:03
memberJochen Arndt23-Jun-12 0:03 
QuestionOnly unist.isu gets installed by visual C++ install shield Pin
adityarao3122-Jun-12 21:30
memberadityarao3122-Jun-12 21:30 
QuestionMFC UI Thread vs. Background Thread Pin
Richard Andrew x6422-Jun-12 11:19
memberRichard Andrew x6422-Jun-12 11:19 
AnswerRe: MFC UI Thread vs. Background Thread [modified] Pin
«_Superman_»22-Jun-12 18:19
member«_Superman_»22-Jun-12 18:19 
SuggestionRe: MFC UI Thread vs. Background Thread Pin
Roger Stoltz23-Jun-12 1:26
memberRoger Stoltz23-Jun-12 1:26 
GeneralRe: MFC UI Thread vs. Background Thread Pin
Richard Andrew x6423-Jun-12 9:31
memberRichard Andrew x6423-Jun-12 9:31 
AnswerRe: MFC UI Thread vs. Background Thread Pin
Vitaly Tomilov23-Jun-12 14:17
memberVitaly Tomilov23-Jun-12 14:17 
AnswerRe: MFC UI Thread vs. Background Thread Pin
fat_boy24-Jun-12 0:55
memberfat_boy24-Jun-12 0:55 
QuestionA Simple C++ Question. Pin
sirama200422-Jun-12 5:19
membersirama200422-Jun-12 5:19 
AnswerRe: A Simple C++ Question. Pin
DavidCrow22-Jun-12 5:47
memberDavidCrow22-Jun-12 5:47 
GeneralRe: A Simple C++ Question. Pin
sirama200426-Jun-12 1:51
membersirama200426-Jun-12 1:51 
AnswerRe: A Simple C++ Question. Pin
Albert Holguin22-Jun-12 6:05
memberAlbert Holguin22-Jun-12 6:05 
AnswerRe: A Simple C++ Question. Pin
Maximilien22-Jun-12 6:26
memberMaximilien22-Jun-12 6:26 
AnswerRe: A Simple C++ Question. Pin
Chuck O'Toole22-Jun-12 9:21
memberChuck O'Toole22-Jun-12 9:21 
GeneralRe: A Simple C++ Question. Pin
jschell22-Jun-12 14:01
memberjschell22-Jun-12 14:01 
AnswerRe: A Simple C++ Question. Pin
Chuck O'Toole23-Jun-12 9:58
memberChuck O'Toole23-Jun-12 9:58 
GeneralRe: A Simple C++ Question. Pin
jschell24-Jun-12 13:06
memberjschell24-Jun-12 13:06 
AnswerRe: A Simple C++ Question. Pin
Chuck O'Toole24-Jun-12 14:29
memberChuck O'Toole24-Jun-12 14:29 
GeneralRe: A Simple C++ Question. Pin
jschell25-Jun-12 10:33
memberjschell25-Jun-12 10:33 
GeneralRe: A Simple C++ Question. Pin
Aescleal23-Jun-12 8:36
memberAescleal23-Jun-12 8:36 
AnswerRe: A Simple C++ Question. Pin
Chuck O'Toole23-Jun-12 9:58
memberChuck O'Toole23-Jun-12 9:58 
GeneralRe: A Simple C++ Question. Pin
Albert Holguin22-Jun-12 11:05
memberAlbert Holguin22-Jun-12 11:05 
QuestionList of driver compilers Pin
Brandon T. H.21-Jun-12 23:37
memberBrandon T. H.21-Jun-12 23:37 
AnswerRe: List of driver compilers Pin
Richard MacCutchan22-Jun-12 2:29
mvpRichard MacCutchan22-Jun-12 2:29 
GeneralRe: List of driver compilers Pin
Brandon T. H.22-Jun-12 18:23
memberBrandon T. H.22-Jun-12 18:23 
GeneralRe: List of driver compilers Pin
Richard MacCutchan22-Jun-12 23:24
mvpRichard MacCutchan22-Jun-12 23:24 
GeneralRe: List of driver compilers Pin
Brandon T. H.23-Jun-12 14:26
memberBrandon T. H.23-Jun-12 14:26 
GeneralRe: List of driver compilers Pin
Richard MacCutchan24-Jun-12 1:16
mvpRichard MacCutchan24-Jun-12 1:16 
GeneralRe: List of driver compilers Pin
fat_boy23-Jun-12 0:31
memberfat_boy23-Jun-12 0:31 
GeneralRe: List of driver compilers Pin
Brandon T. H.23-Jun-12 15:10
memberBrandon T. H.23-Jun-12 15:10 
GeneralRe: List of driver compilers Pin
Brandon T. H.23-Jun-12 15:10
memberBrandon T. H.23-Jun-12 15:10 

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

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


Advertise | Privacy | Mobile
Web03 | 2.8.150428.2 | Last Updated 5 May 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid