CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Byte Conversion

  1. #1
    Join Date
    Oct 2001
    Posts
    745

    Byte Conversion

    I have a Problem with bytes.wstring in windows is 2 bytes & in linux 4 bytes.
    In windows Iam doing as follows:
    "Text" is of type Wstring.

    char buffer[1];
    int len = Text.size()*2;
    // Converting to char
    char *p = (char*)Text.c_str();

    // here an algoritham,so that Iam taking the 1st 2 bytes .Iam doing this because,I want to swap the bytes(Little to BigEndian).& Iam writing it to stream.

    for(int i=1; i<=len; i+=2)
    {
    for(int j =0;j<=1;j++)
    {
    buffer[j] = *p;
    p++;
    if (j ==1)
    {
    stream.write((Little2BigEndian(buffer,2)),2);
    }
    }
    }

    Little2BigEndian Function Does the swap.So In linux I want to convert the 4 bytes to bytes.How to do in accordance with my code .

    Could any one Help?

    Thanks

  2. #2
    Join Date
    Aug 2001
    Location
    germany
    Posts
    772

    Byte Conversion

    You could try to program a function which finds out which operatign system is installed and dle your conversion accordingly.

  3. #3
    Join Date
    Oct 2001
    Posts
    745
    Iam # defining for Linux & windows,Could any one tell it with a code snippet please

  4. #4
    Join Date
    Aug 2001
    Location
    germany
    Posts
    772

    Byte Conversion

    you can find a function for which finds out the Windows Version at:

    http://msdn.microsoft.com/library/de...sinfo_49iw.asp

    I don't know how it is for Linux.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured