Click here to Skip to main content
16,010,416 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalgetting info about another process Pin
subir talukder4-Jan-01 1:37
subir talukder4-Jan-01 1:37 
GeneralMake Controls Invisible Pin
3-Jan-01 14:58
suss3-Jan-01 14:58 
GeneralRe: Make Controls Invisible Pin
Michael Dunn3-Jan-01 15:18
sitebuilderMichael Dunn3-Jan-01 15:18 
GeneralRe: Make Controls Invisible Pin
Masoud Samimi4-Jan-01 6:25
Masoud Samimi4-Jan-01 6:25 
QuestionAlternate CA for NT security? Pin
Jonathan Gilligan3-Jan-01 12:36
Jonathan Gilligan3-Jan-01 12:36 
General2's compliment Pin
Mike Zolna3-Jan-01 10:47
Mike Zolna3-Jan-01 10:47 
GeneralRe: 2's compliment Pin
Michael Dunn3-Jan-01 15:25
sitebuilderMichael Dunn3-Jan-01 15:25 
GeneralRe: 2's compliment Pin
Tim Deveaux4-Jan-01 8:34
Tim Deveaux4-Jan-01 8:34 
I'm assuming you have FD as text, and need to convert it. I don't think there's a built in way to do this. Some searching reveals a couple of 'hex string to value' conversion routines, one in SNA. Found HEX2INT.PRG in the docs for FoxPro 2.5 for DOS... hmmm...

Oh well, never pass up a chance to fill up a message with a nice pale orange block...

// FD.cpp : Defines the entry point for the console application.
//
 
#include <iostream>
 
using namespace std;
 
long Hex2Int(char * pszHex) {
 
    static unsigned char byteLookup[22][2]  =  
    {   '0', 0, '1', 1, '2', 2, '3', 3, '4', 4, '5', 5, '6', 6, '7', 7, 
        '8', 8, '9', 9, 'A', 10,'B', 11,'C', 12,'D', 13,'E', 14,'F', 15,
        'a', 10,'b', 11,'c', 12,'d', 13,'e', 14,'f', 15
    };
 
    register long total = 0;
 
    int  nPosition = 0;
 
    if(*pszHex) {
 
        register int len = strlen(pszHex) - 1;
 
        while (len >= 0) {
            bool bFound = false;
            int i;
            for (i = 0; i < sizeof(byteLookup)/2; ++i) {
                if(byteLookup[i][0] == *(pszHex+len)) {
                    ++bFound;
                    break;
                }
            }
 
            // didn't find the character in the lookup, so throw.
            if(!bFound) throw "Invalid hex number\n";
 
            if(nPosition == 0) {
                total = byteLookup[i][1];
            }
            else {
                // use left shift to multiply the next value
                total += byteLookup[i][1] << (4 * nPosition);
            }
            
            --len;
            ++nPosition;

            // can only handle up to 32 bits (for this implementation anyway) so throw.
            if (nPosition > 8) throw "Too many hex digits\n";
 
        }
        // here, we could have code to extend the high order bits if the string is < 8 chars
        // and begins with a char/lookup '8' or greater.  The way things work now, you need 
        // to pass an 8 char string starting with '8' or better to get a signed result
        // Any takers???  
 
    }
    else {
        // Empty string was passed in, so throw as well, rather than return 0
        throw "Empty string\n";
    }
 
    return total;
}
 
int main(int argc, char* argv[])
{
    char s[255];
    long result = -1;
 
    while (result) {
        cout << endl << "Enter a hex number please, or 0 to exit: ";
        
        cin >> s;
        
        try {
            result = Hex2Int(s);
            cout << endl << "Hex2Int returned " << dec << result << " [" << hex << result << "]" << endl;
        }
        catch (char * e) {
            cout << e;
        }
    }
 
    return 0;
}


Note that there's room for optimization here, and there's the issue (see comments) of sign extension. This Hex2Int returns 253 for FD, -3 for FFFFFFFD. But I think you need something like this to do the translation.
QuestionGZIP file compression suggestions? Pin
Josh Knox3-Jan-01 9:30
Josh Knox3-Jan-01 9:30 
AnswerRe: GZIP file compression suggestions? Pin
Jonathan Gilligan3-Jan-01 12:25
Jonathan Gilligan3-Jan-01 12:25 
GeneralGetDeviceCaps, C1_TRANSPARENT, CAPS1 and NEWTRANSPARENT Pin
Marc Richarme3-Jan-01 8:31
Marc Richarme3-Jan-01 8:31 
GeneralRe: GetDeviceCaps, C1_TRANSPARENT, CAPS1 and NEWTRANSPARENT Pin
3-Jan-01 10:22
suss3-Jan-01 10:22 
GeneralGetting terminal output in HEX format Pin
3-Jan-01 7:20
suss3-Jan-01 7:20 
GeneralRe: Getting terminal output in HEX format Pin
Tim Deveaux3-Jan-01 10:04
Tim Deveaux3-Jan-01 10:04 
GeneralIf the contents of file modified outside the editor Pin
3-Jan-01 5:10
suss3-Jan-01 5:10 
GeneralWAVEFORMATEX Pin
Roger3-Jan-01 4:58
Roger3-Jan-01 4:58 
GeneralFormatMessage Pin
3-Jan-01 2:33
suss3-Jan-01 2:33 
GeneralRe: FormatMessage Pin
3-Jan-01 4:19
suss3-Jan-01 4:19 
GeneralRe: FormatMessage Pin
3-Jan-01 23:44
suss3-Jan-01 23:44 
QuestionIs this method to get defaullt domain name correct? Pin
3-Jan-01 2:30
suss3-Jan-01 2:30 
GeneralHOWTO : Insert Office Documents into a Dialog base apps Pin
jerry0davis3-Jan-01 1:28
jerry0davis3-Jan-01 1:28 
QuestionAnyone know where I can get a class that plays MP3 via DirectSound ? Pin
Christian Graus2-Jan-01 20:02
protectorChristian Graus2-Jan-01 20:02 
AnswerRe: Anyone know where I can get a class that plays MP3 via DirectSound ? Pin
Erik Funkenbusch3-Jan-01 6:51
Erik Funkenbusch3-Jan-01 6:51 
GeneralRe: Anyone know where I can get a class that plays MP3 via DirectSound ? Pin
Christian Graus3-Jan-01 9:38
protectorChristian Graus3-Jan-01 9:38 
GeneralRe: Anyone know where I can get a class that plays MP3 via DirectSound ? Pin
Erik Funkenbusch3-Jan-01 13:53
Erik Funkenbusch3-Jan-01 13:53 

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.