rounding off to the next nearest 0x100
-
- Posts: 81
- Joined: Sun Jul 10, 2016 11:07 am
rounding off to the next nearest 0x100
not sure what it is really is called but id like to now how to achieve this by bms script
like if the size it 0xF2DA it will output 0xF300
or if the size it 0x3A2DA it will output 0x3A300
really not sure how to do this
this is my closest miserable attempt to make one but it's still wrong...
set SIZE long 0xF2DA
xmath TEST2 "(SIZE & 0xF00) + 0x100"
xmath TEST3 "(SIZE & 0xF000) + TEST2"
it will output 0xF300 but if I input like 0x2F300 it will still output 0xF300
like if the size it 0xF2DA it will output 0xF300
or if the size it 0x3A2DA it will output 0x3A300
really not sure how to do this
this is my closest miserable attempt to make one but it's still wrong...
set SIZE long 0xF2DA
xmath TEST2 "(SIZE & 0xF00) + 0x100"
xmath TEST3 "(SIZE & 0xF000) + TEST2"
it will output 0xF300 but if I input like 0x2F300 it will still output 0xF300
-
- Site Admin
- Posts: 12984
- Joined: Wed Jul 30, 2014 9:32 pm
Re: rounding off to the next nearest 0x100
math SIZE x 0x100
Yeah it's really that easy
Yeah it's really that easy
-
- Posts: 706
- Joined: Fri Aug 08, 2014 1:06 am
Re: rounding off to the next nearest 0x100
here try this
Code: Select all
set SIZE long 0x3A2DA
print "%SIZE|hex% :size"
xmath CHECK "SIZE % 256"
print "%CHECK|hex% :check"
if CHECK != 0
xmath SIZE "(SIZE - CHECK) + 256"
print "%SIZE|hex% :new size"
endif
print "%SIZE|hex% :final size"
-
- Site Admin
- Posts: 12984
- Joined: Wed Jul 30, 2014 9:32 pm
Re: rounding off to the next nearest 0x100
@Acewell
Why? Isn't "math SIZE x 0x100" better?
Why? Isn't "math SIZE x 0x100" better?
-
- Posts: 16
- Joined: Sun Dec 28, 2014 3:02 pm
Re: rounding off to the next nearest 0x100
.
Could you kindly paste the source code for the math x command? I'd like to port it to a C# tool I'm working on.
Lucky coincidence this showed up on my twitter feed yesterday when I ran into the problem
Could you kindly paste the source code for the math x command? I'd like to port it to a C# tool I'm working on.
Lucky coincidence this showed up on my twitter feed yesterday when I ran into the problem
-
- Site Admin
- Posts: 12984
- Joined: Wed Jul 30, 2014 9:32 pm
Re: rounding off to the next nearest 0x100
var1 is the number to round and var2 is the alignment (for example 0x100):
Code: Select all
if(var2 && ((u_int)var1 % (u_int)var2)) { var1 += (var2 - ((u_int)var1 % (u_int)var2)); }
-
- Posts: 16
- Joined: Sun Dec 28, 2014 3:02 pm
Re: rounding off to the next nearest 0x100
Thank you!
-
- Posts: 706
- Joined: Fri Aug 08, 2014 1:06 am
Re: rounding off to the next nearest 0x100
aluigi wrote:Isn't "math SIZE x 0x100" better?
oh wait, that "x" is a special operator isn't it?
i was thinking you meant "times", like 2 x 2 = 4
first time i saw that "x" used, you never mentioned this solution to my "maintain a multiple of 4" problem here
viewtopic.php?f=13&t=3952
both ways work, but can you round down with your solution?
ah i see you have a "y" operator for that
Last edited by Acewell on Mon Apr 24, 2017 9:47 pm, edited 2 times in total.
-
- Site Admin
- Posts: 12984
- Joined: Wed Jul 30, 2014 9:32 pm
Re: rounding off to the next nearest 0x100
Eh, when I see long posts I can't focus on them and, in that case I just focused only on the script you posted almost ignoring the rest
Anyway you can find all the operators in quickbms.txt, 'x' is there.
Anyway you can find all the operators in quickbms.txt, 'x' is there.
-
- Posts: 81
- Joined: Sun Jul 10, 2016 11:07 am
Re: rounding off to the next nearest 0x100
thanks for the reply! gonna try some of the examples you guys gave.