Thread: Type Conversions

  1. #1
    Registered User
    Join Date
    Mar 2005

    Type Conversions

    Im pulling in data through a winsock. The data im pulling in in of type Unsigned Char , Ive see an example that uses the following to displayed the data correctly

    Is there any other way to do this, possibly using cout? I also want to convert the data, and then compare it in a switch. Any ways to convert it besides that printf() would be appricated. Thanks.

  2. #2
    Registered User
    Join Date
    Aug 2002
    Hermosa Beach, CA
    The conversion is being done by htons, not by printf, so:

    short value = htons(pTcpheader->Flags);
    cout << "Flags = " << value;
    switch (value) {
        // do whatever ...
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Oregon, USA
    If it's only unsigned char then you don't need htons(). You only need to worry about endianness when the data is more than 1 byte.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  2. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM