PHO - Pokémon Hackers Online
Go Back   PHO - Pokémon Hackers Online > Discussion Board > Archive

Notices

Archive Old threads that serve no purpose are here.

 
 
Thread Tools Display Modes
Old 1st September 2013, 03:08 PM   #11
karatekid552
What does this button do?.....
Ex-Staff
 
karatekid552's Avatar
 
Join Date: Feb 2013
Location: Stalker.......
Posts: 229
karatekid552 karatekid552
Default

Quote:
Originally Posted by Miksy91 View Post
You're welcome!
Though I won't let you go so easily with it just yet :P (since according to this comment, you possibly haven't caught the little-endian format just yet).

In big endian, bytes are in normal order. In little-endian bytes are in reversed order.
Bytes consists of 8 bits. In other words, bytes are 8-bit queues/sequences (don't know the right word in english so I picked up two that an internet wordbook gave me).

Now if we again think about a hexadecimal value xA7DF.

In big endian, it is represented as A7 DF.
A7|DF
-----
1010 0111|1101 1111

In little-endian, it is represented as DF A7.
DF|A7
------
1101 1111|1010 0111

As you can see, bit 0 won't go to the place of bit 15 - it goes to the place of bit 8. That's because the order of the bytes (or 8-bit queues!) change - not the order of bits.
Actually, I did catch that. However, now that I am thinking about it, how do I know which one to count as 15. Like, say GBATEK specifies a bit, how do I know which bit to start counting from? Are we taking the big endian format and reading left to right, 0->15?

Let's say I want to overwrite one of the i/o registers with custom settings.

At the bottom of my ASM, I would write:

New_IO_Settings: .hword 0x[SettingsinBigEndian]

When it gets compiled and copied into the ram, it will be converted into little endian.

So, which is the one I count?

Would I do:

1) New_IO_Settings: .hword 0x[Bits 0-15]

2) New_IO_Settings: .hword 0x[Bits 15-0]

3) New_IO_Settings: .hword 0x[Bits 7-0, Bits 15-8]


I understand how the bytes get shifted between the two formats, but my main issue is which format is GBATEK using when it defines something?
karatekid552 is offline  
Sponsored Links
Old 1st September 2013, 03:57 PM   #12
Miksy91
Gotta fill something here.
 
Miksy91's Avatar
 
Join Date: Jul 2013
Location: Northern Europe
Age: 27
Posts: 117
Miksy91
Default

I don't use GBATEK, so I can't help you with that I'm afraid :P
But why don't you just test it out and see how it works?

Though this
Quote:
Originally Posted by karatekid552
1) New_IO_Settings: .hword 0x[Bits 0-15]
might just give the wanted results, since that's a human friendly way of programming a tool to work.

If not, you've got to write the New_IO_Settings in little-endian.
__________________

Last edited by Miksy91; 1st September 2013 at 03:59 PM.
Miksy91 is offline  
Old 1st September 2013, 07:32 PM   #13
karatekid552
What does this button do?.....
Ex-Staff
 
karatekid552's Avatar
 
Join Date: Feb 2013
Location: Stalker.......
Posts: 229
karatekid552 karatekid552
Default

Quote:
Originally Posted by Miksy91 View Post
I don't use GBATEK, so I can't help you with that I'm afraid :P
But why don't you just test it out and see how it works?

Though this

might just give the wanted results, since that's a human friendly way of programming a tool to work.

If not, you've got to write the New_IO_Settings in little-endian.
Okay, thanks. I'll give it a try and see what happens. Or, I'll just look at something where one of the bytes is coordinates and then I'll know. One sec...
karatekid552 is offline  
Old 25th November 2013, 05:06 PM   #14
mewthree9000
Junior Trainer
 
mewthree9000's Avatar
 
Join Date: May 2010
Location: U.S.A.
Age: 28
Posts: 70
mewthree9000 mewthree9000
Default

Super helpful thread! Thanks guys!
__________________
-Mewthree9000
We all fight a war within ourselves, a war of greatness, a war to become the best.
LIVE THE REVOLUTION, PHO!
Gotta Hack'em All!!




My current projects:
-Pokemon ChaosBlack[v2]
-!!Elite FireRed ROM Base!!
mewthree9000 is offline  
Likes Miksy91 liked this post
Old 7th January 2014, 10:34 PM   #15
karatekid552
What does this button do?.....
Ex-Staff
 
karatekid552's Avatar
 
Join Date: Feb 2013
Location: Stalker.......
Posts: 229
karatekid552 karatekid552
Default

I learned how to convert binary and decimal in my head about a week or so ago. This may be really useful to someone, so I'll share it here:

The bits in binary are actually powers of two:

0b1 = 1
0b10 = 2
0b100 = 4
0b1000 = 8
and so on.

So, to convert binary to decimal, just add up the totals for bits. Let's say we have an 8 bit number, 10100111. Let's add them up:

_1_|_0|_1|_0|0|1|1|1
128|64|32|16|8|4|2|1

_1_|_0|_1|_0|0|1|1|1
128|64|32|16|8|4|2|1

128+32+4+2+1
160+6+1
166+1
167

So, it really isn't that hard to convert binary and decimal. To do the other way, just reverse it. Let's use the number 286.

The largest power of 2 that fits inside of it is 256, so we know we will have a 9 bit number. So, begin by setting up a quick table. You already know what the first digit is, so fill that in:

1|_|_|_|_|_|_|_|_

Now, the next digit is 128.

286 - 256 = 30. 128 doesn't fit.

1|0|_|_|_|_|_|_|_

Neither does 64.

1|0|0|_|_|_|_|_|_

30? No.

1|0|0|0|_|_|_|_|_

16? Yeah!

1|0|0|0|1|_|_|_|_

Hmmm, 30-16 = 14

So, 8? Yes.

1|0|0|0|1|1|_|_|_

14-8 = 6

So, 4? Yes.

1|0|0|0|1|1|1|_|_

Now, 6-4=2

So 2 is a go.

1|0|0|0|1|1|1|1|_

Now that we have exausted our resources, we know that there is no 1's place, so that is filled with a 0.

1|0|0|0|1|1|1|1|0

and 100011110 is our final answer for 286 in binary!

Hope this helps anyone!
karatekid552 is offline  
Likes Miksy91 liked this post
Old 8th January 2014, 05:41 PM   #16
Miksy91
Gotta fill something here.
 
Miksy91's Avatar
 
Join Date: Jul 2013
Location: Northern Europe
Age: 27
Posts: 117
Miksy91
Default

Adding what karatekid552 just wrote here, doing the same thing between binary and hex is (in my personal opinion) even more simple. So instead of counting these powers on head in decimal, let's try hexadecimal!

Code:
Example;
Convert 0xBD to binary.
 
0xBD - 0x80 = 0x3D ---> 1
 
0x3D < 0x40 --> 0
 
0x3D - 0x20 = 0x1D --> 1
 
0x1D - 0x10 = 0xD --> 1
 
0xD - 0x8 = 0x5 --> 1
 
0x5 - 0x4 = 0x1 --> 1
 
0x1 < 0x2 --> 0
 
0x1 - 0x1 = 0x0 --> 1
Now with the same method karatekid552 showed, we can form the binary number this hexadecimal number responds.

1011 1101


So basically, the real use behind converting between hexadecimal and binary like this is the fact, how easily each power of two can be described in hexadecimal. See;

0x0, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, ...
__________________
Miksy91 is offline  
Likes karatekid552 liked this post
 

Tags
<>, binary, conversions, hex, simple, [Guide]

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:20 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc. User Alert System provided by Advanced User Tagging (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
Pokémon characters and images belong to Pokémon USA, Inc. and Nintendo.
Pokémon Hackers Online (PHO) is in no way affiliated with or endorsed by Nintendo LLC, Creatures, GAMEFREAK inc,
The Pokémon Company, Pokémon USA, Inc., The Pokémon Company International, or Wizards of the Coast.
All forum/site content (unless noted otherwise) and site designs are © 2006-2013 Pokémon Hackers Online (PHO).
Green Charizard Christos TreeckoLv100

"Black 2" by ARTPOP. Kyurem artwork by XOUS.

no new posts