Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


ascii to byte

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Tue Mar 24, 2009 8:09 am    Post subject: ascii to byte Reply with quote

how to go from ASCII to Byte?
I've got the following code:

Code:


       char buf[256];


   for(;;)
   {
      rc = recv(DestSocket,buf,sizeof(buf), 0);
      printf("Received from Client: %s\n",buf);
   }
   return 0;


Now i get the input like on the picture.

but I wanna convert it to bytes.
Like this

Received from Client hi => buf[] = {0x48, 0x61};
So it's easier for me to see what packets have been sent.



Data.JPG
 Description:
 Filesize:  29.25 KB
 Viewed:  7157 Time(s)

Data.JPG




Last edited by blackmorpheus on Tue Mar 24, 2009 8:48 am; edited 1 time in total
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Tue Mar 24, 2009 9:03 am    Post subject: Reply with quote

not sure which way you wanted to go but it is equally easy to typecast the other way

Code:
#include "stdafx.h"
#include "windows.h"
#include <conio.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
   int buf[] = {0x48, 0x61};
   
   for ( int i = 0; i < (sizeof (buf)/sizeof (int)); i++ )
      cout << (char)buf[i];

   while(!_kbhit())
      Sleep(100);

   return 0;
}



lalalala.jpg
 Description:
 Filesize:  180.47 KB
 Viewed:  7138 Time(s)

lalalala.jpg


Back to top
View user's profile Send private message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Tue Mar 24, 2009 9:08 am    Post subject: Reply with quote

the other way around is a bit trickier i think..
can u show how?
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Tue Mar 24, 2009 9:18 am    Post subject: Reply with quote

how about..

Code:
#include "stdafx.h"
#include "windows.h"
#include <conio.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
   int buf[] = {0x48, 0x61};
   char charbuf[] = { 'H', 'a' };
   
   for ( int i = 0; i < (sizeof (buf)/sizeof (int)); i++ )
      cout << (char)buf[i];

   for ( int i = 0; i < sizeof charbuf; i++ )
      cout << "\n0x" << hex << (int)charbuf[i];

   while(!_kbhit())
      Sleep(100);

   return 0;
}


is that what he wants to do ?



poopie.jpg
 Description:
 Filesize:  183.7 KB
 Viewed:  7126 Time(s)

poopie.jpg


Back to top
View user's profile Send private message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Tue Mar 24, 2009 10:17 am    Post subject: Reply with quote

Thanks all, fixed it.
I didn't need the iostream so just used stdio.h.



Data2.JPG
 Description:
 Filesize:  68.2 KB
 Viewed:  7110 Time(s)

Data2.JPG


Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites