andrew 

Group: Super Administrators
Posts: 635
Joined: Oct. 2003
Member Rating: 4
|
 |
Posted on: May 13 2009,07:38 |
|
 |
The calculator in HexEdit 3.4 has had a major revamp. The most noticable things are the new "XP style" buttons and the menu buttons at the top of the window.
However, there are many other improvements. First, the resize behaviour has been improved -- you may not know that the calculator is resizable, which can be very useful when it is docked next to another modeless dialog.
Precedence
It has been pointed out (thanks Anthony) that the calculator does not support the normal operator precedence for binary operators. (Binary operations are those that take 2 operands and appear to the right of the number keys on the HexEdit calculator.) So 1 + 2 * 3 = 7 (not 9) since * has a higher precedence than +. This behavior was actually by design for several reasons some of which are:
- the Windows calculator does (did) not support operator precedence - simple electronic calculators usually do not support operator precedence - there is no standard mathematical precedence of some operators (shifts etc) - calculators that do have precedence are error-prone as you cannot see the pending operations
But the main reason is that I had always intended to allow an integer expression to be entered into the calculator, which can now be done in HexEdit 3.4. The advantage of this is that you can see exactly the expression to be evaluated with full precedence (as implemented in C/C++ expressions), and add brackets if you are unsure of the precedence of any operations.
So now you have two choices:
- use the calculator buttons for simple calculations where precedence is not required - enter an integer expression for more complex calculations with precedence (and brackets)
Non-integer expressions
Not only can you enter integer expressions into the calculator but you can also enter expressions of the 4 other types supported by HexEdit. When the result of an expression is not an integer then a letter is displayed next to the result to indicate the type (in the same place that the "O" is displayed to indicate integer overflow). The letters are:
R: real S: string B: boolean D: date
When the result is not an integer many of the calculator buttons do not make sense, since they are designed to work only with integers. For example, an address to jump to can only be an integer.
However, an expression can have operands of any type and still give an integer result. For example, the expression:
"ABC" < "DEF" ? 1 : 2
contains 2 strings and a boolean (the result of the comparison) but in the end returns an integer.
Expressions can also use (and assign to) variables, including arrays. For example:
J=1, K=2, a[J][K]=J+K
This assigns to the variables J, K and a[1][2]. If variables do not exists they are created with the type of the expression that is assigned to them.
Note that currently expressions support all operators used in C/C++ expressions except for some that have side effects. The ++ and -- operators as well as assignment operators (except =) are not supported. However, all others, including the ternary and comma operators are supported. Further, brackets and the nromal C/C++ precedence are used. See a C manual for details.
Menu buttons
At the top of the calculator window are 4 new buttons that display drop-down menus when clicked. These are:
Hex Jump History - a history list of previous file jumps made in the hex jump tool or in the calculator (using the Go button) when in hex mode
Dec Jump History - a history list of previous file jumps made in the decimal jump tool or in the calculator (using the Go button) when in decimal mode
Variables - all currently assigned variables, grouped into sub-menus by type (see below)
Functions - all available functions, grouped into sub-menus by type (see further below)
Variables
New variables can be created when they are assigned to, either by entering a expression into the calculator or one of the jump tools. For example, you can enter this into the hex jump tool:
LAST=FFFF
which will assign the value 65,535 ($FFFF) to the variables LAST (as well as jumping to that address).
Depending on the curcumstances it may be ambiguous whether a value is a hex number or a variable name. For example, if you enter this into the decimal jump tool (or the calculator in decimal mode):
AB = 3
then entering AB into the hex jump tool will jump to 171 ($AB) rather than 3. You can precede a variable name with @ to avoid this problem, so that entering @AB would jump to address 3.
Note that all variables are retained when HexEdit is closed. (Variables created in jump tools have been saved to the registry since HexEdit 2.5.) Hence you can use them to remember imprortant addresses or values. (Bookmarks are better in that they remember an address and a file name.)
You can clear all variables using the "Clear All Variables" menu item in the Variables menu.
Functions
The functions drop-down menu allows you to see and select any of the pre-defined functions available in expressions. (Actually there are a few other functions such as "addressof" that are only available in templates since they make no sense in normal expressions.)
The functions are grouped into sub-menus according to the 5 expression types.
Note that some functions you might expect are not present as they are implemented as operators. For example, there is no "strcmp" function as you can compare strings directly using ==, != < etc.
Another thing that is not obvious from the menus is that the min and max functions can take any number of parameters. So the expression
min(5, 7, 3, 9)
will return 3.
Edited by andrew on Feb. 16 2010,01:53
-------------- Andrew Phillips Moderator of Forums and creator of Hex Edit
|