Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. hex converting

hex converting

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
22 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N NewHSKid

    but I only need 4 bytes? should i change the 32 to 4 then? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #13

    You don't need this at all. Dangleberry's post was just showing you how to convert a number to a string (which was then displayed in a message box).

    1 Reply Last reply
    0
    • D David Crow

      Bingo!! These three code snippets are the same: int num = 123456789; // base-10 SendToServer(num); int num = 0x75BCD15; // base-16 SendToServer(num); int num = 0726746425; // base-8 SendToServer(num);

      N Offline
      N Offline
      NewHSKid
      wrote on last edited by
      #14

      For the send command, i have problems it needs the socket and a message and a length, and some flags. Its says I can't use int because the message has to be const char *. for the length is that in bytes? should it be 4 or 10 to represent all numbers/letters? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

      D 1 Reply Last reply
      0
      • N NewHSKid

        For the send command, i have problems it needs the socket and a message and a length, and some flags. Its says I can't use int because the message has to be const char *. for the length is that in bytes? should it be 4 or 10 to represent all numbers/letters? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #15

        How about a code snippet of what you are trying to do?

        N 1 Reply Last reply
        0
        • D David Crow

          How about a code snippet of what you are trying to do?

          N Offline
          N Offline
          NewHSKid
          wrote on last edited by
          #16

          hi, here is what i want to do, the program is connected to the server already. (I don't know how to connect, i just use my friends dad program to connect) int message; message = 0x5FF0023A; send(s, message, strlen(message), 0); It says send can't convert parameter 2 from int to const char * and it says the same thing about strlen. Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

          D L 2 Replies Last reply
          0
          • N NewHSKid

            hi, here is what i want to do, the program is connected to the server already. (I don't know how to connect, i just use my friends dad program to connect) int message; message = 0x5FF0023A; send(s, message, strlen(message), 0); It says send can't convert parameter 2 from int to const char * and it says the same thing about strlen. Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #17

            NewHSKid wrote: the program is connected to the server already. (I don't know how to connect, i just use my friends dad program to connect) Does that mean he is supplying you with a valid socket descriptor? Given that the second parameter of send() is expecting a char*, you'll need:

            int nMessage = 0x5FF0023A;
            char szMessage[9]; // hold 8 characters plus a \0
            sprintf(szMessage, "%d", nMessage); // or itoa(nMessage, szMessage, 16);
            int nBytes = send(s, szMessage, lstrlen(szMessage), 0);

            N 1 Reply Last reply
            0
            • D David Crow

              NewHSKid wrote: the program is connected to the server already. (I don't know how to connect, i just use my friends dad program to connect) Does that mean he is supplying you with a valid socket descriptor? Given that the second parameter of send() is expecting a char*, you'll need:

              int nMessage = 0x5FF0023A;
              char szMessage[9]; // hold 8 characters plus a \0
              sprintf(szMessage, "%d", nMessage); // or itoa(nMessage, szMessage, 16);
              int nBytes = send(s, szMessage, lstrlen(szMessage), 0);

              N Offline
              N Offline
              NewHSKid
              wrote on last edited by
              #18

              Hi, Thanks for helping. So when i use that code, the receiving program will get the hex number of 5FF0023A? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

              D 1 Reply Last reply
              0
              • N NewHSKid

                hi, here is what i want to do, the program is connected to the server already. (I don't know how to connect, i just use my friends dad program to connect) int message; message = 0x5FF0023A; send(s, message, strlen(message), 0); It says send can't convert parameter 2 from int to const char * and it says the same thing about strlen. Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #19

                try this : send(s, (const char FAR*)message, sizeof(message), 0); though the sizeof(message) param can just be 0, as message oriented sockets will send a zero-length transport datagram. :cool:

                1 Reply Last reply
                0
                • N NewHSKid

                  Hi, Thanks for helping. So when i use that code, the receiving program will get the hex number of 5FF0023A? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #20

                  No, the recv() function on the other end will receive "5FF0023A" as a char*. It can convert that to an integer (long actually) with strtol(). long lMessage; char szMessage[9], *stop; int nBytes = recv(s, szMessage, sizeof(szMessage), 0); lMessage = strtol(szMessage, &stop, 16);

                  1 Reply Last reply
                  0
                  • N NewHSKid

                    My friends dad gave me a program to write cause he said it will make me learn. I have to connect to a server and send it 4 byte messages that have the form of 5FF00239. The message changes though, because the window (dialog i think its called) has 2 check boxes. If only the first check box is checked then the message should be 5FF00239 and if the second check box is only check it should be 5FF0023A. But if both are checked then he wants the message to be 5FF0023B. How do I make these messages? I don't know what type they should be. I can do everything else he wants except i don't know how to do the message. I thought it would be a string, but he says if it is, then the message is 8 bytes instead of 4? Please help me...

                    K Offline
                    K Offline
                    Ken Mazaika
                    wrote on last edited by
                    #21

                    Windows Sockets can be highly complicated as well as windows programming for people somewhat new to programming. From your posts it seems as if your skipping quite a few steps in the learning process. I think if you ended up writing a program that does what you want now it will be mostly cut/paste code and you won't get much out of the experience. This program would be an excellent learning experience, but you should make creating it more of a long range goal.

                    1 Reply Last reply
                    0
                    • N NewHSKid

                      but I only need 4 bytes? should i change the 32 to 4 then? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

                      T Offline
                      T Offline
                      Terry ONolley
                      wrote on last edited by
                      #22

                      The only actual "numbers" in the computer are semi-conductor gates that are either on or off. That is fine for the computer, but most people need something visual to help us understand what is going on. To the computer, all numbering base sytems look the same - binary. It is only when outputting the graphical representation of those numbers that you need to worry about data types and base. So, the number 255 is represented in the coputer by 8 logic gates being on: 11111111 If you, the human, wants to see that number in hexadecimal, then you tell your program to format that number in base 16 and you see "FF". Now, the characters "FF" are represented by the ascii code for the letter 'F' - which is 70 or x40 - so if you looked at the raw bits for the characters "FF" you would see 70 70 or the bits 01000110, 01000110. So what happened??? You started with 11111111 and ended up with 01000110, 01000110! The confusion comes from figuring out what format the reciever of the data is expecting. That is what function headers are for. They define how to interperet the bits that are being sent.



                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups