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 


writing to HiWord LoWord

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

Joined: 06 Sep 2009
Posts: 131
Location: Greece

PostPosted: Sat Mar 06, 2010 10:16 am    Post subject: writing to HiWord LoWord Reply with quote

I have an array of bytes, and a WORD. I want to write the 2 bytes seperately in the WORD. How should I do it. Example

Code:

WORD TheWord;
BYTE Bytes[100]; <-- say this is full with values.

TheWord = Bytes[0]; <-- High
TheWord = Bytes[1]; <-- Low


If I do that, only the Low Word will be written, the High Word will be empty.
Please help to do it.

EDIT: I am thinking now,, if I multiply the high byte with 256 will give the high word value. Eg. I want to write 0xB6.

0xB6 * 256 = 0xB600 and then just adding up the low word??


Last edited by kot1990 on Sat Mar 06, 2010 10:26 am; edited 1 time in total
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sat Mar 06, 2010 10:26 am    Post subject: Re: writing to HiWord LoWord Reply with quote

kot1990 wrote:
I have an array of bytes, and a WORD. I want to write the 2 bytes seperately in the WORD. How should I do it. Example

Code:

WORD TheWord;
BYTE Bytes[100]; <-- say this is full with values.

TheWord = Bytes[0]; <-- High
TheWord = Bytes[1]; <-- Low


If I do that, only the Low Word will be written, the High Word will be empty.
Please help to do it.

Derrp look at your code... you're rewriting "TheWord".
Back to top
View user's profile Send private message
kot1990
Expert Cheater
Reputation: 1

Joined: 06 Sep 2009
Posts: 131
Location: Greece

PostPosted: Sat Mar 06, 2010 10:30 am    Post subject: Re: writing to HiWord LoWord Reply with quote

&Vage wrote:
Derrp look at your code... you're rewriting "TheWord".


yes I know,, what I want to do when writing the High Word,, is that I want to distinguish it, so it will write on the high Word , and not the low word, so I won't rewrite the Low Word.
Back to top
View user's profile Send private message
AtheistCrusader
Grandmaster Cheater
Reputation: 6

Joined: 23 Sep 2006
Posts: 681

PostPosted: Sat Mar 06, 2010 10:51 am    Post subject: Reply with quote

Code:

#include <Windows.h>
#include <iostream>
using namespace std;
int main()
{
   BYTE Byte = 64;
   BYTE byte = 65;
   LONG TheWord;
   TheWord = MAKELONG(Byte,byte);
   cout << LOWORD(TheWord) << "  " << HIWORD(TheWord)  <<  endl;
   system("PAUSE");
}
Back to top
View user's profile Send private message
kot1990
Expert Cheater
Reputation: 1

Joined: 06 Sep 2009
Posts: 131
Location: Greece

PostPosted: Sat Mar 06, 2010 10:57 am    Post subject: Reply with quote

Thx man Smile I'll keep in mind,, I found another way to do it like

Code:

WORD TheWord;
BYTE Bytes[100]; <-- say this is full with values.

TheWord = Bytes[0] * 256; <-- High
TheWord += Bytes[1]; <-- Low
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Sat Mar 06, 2010 1:23 pm    Post subject: This post has 1 review(s) Reply with quote

Code:
WORD TheWord;
BYTE Bytes[100]; <-- say this is full with values.

TheWord = Bytes[0] << 8 | Bytes[1];

Just to note: the following would use Bytes[0] as low word and Bytes[1] as high word:
Code:
TheWord = *(WORD*)&Bytes[0];
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Mar 06, 2010 5:38 pm    Post subject: Re: writing to HiWord LoWord Reply with quote

kot1990 wrote:
I have an array of bytes, and a WORD. I want to write the 2 bytes seperately in the WORD. How should I do it. Example

Code:

WORD TheWord;
BYTE Bytes[100]; <-- say this is full with values.

TheWord = Bytes[0]; <-- High
TheWord = Bytes[1]; <-- Low


If I do that, only the Low Word will be written, the High Word will be empty.
Please help to do it.

EDIT: I am thinking now,, if I multiply the high byte with 256 will give the high word value. Eg. I want to write 0xB6.

0xB6 * 256 = 0xB600 and then just adding up the low word??


I think you were aiming for something like this?

Code:
int main()
{
   WORD   dongs;
   WORD   w = 0x1234;
   BYTE*   b = (BYTE*)&w;


   b[0] += 1; //b[0] is 0x34 before the addition
   b[1] += 1; //take a guess

   dongs = (WORD)(b[0] | b[1] << 8); //or...
   dongs = *(WORD*)b;

   return 0;
}


you can just use a bitwise or to 'combine', just make sure you shift appropriately... or you can just cast it.
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