No BSD License  

Highlights from
Hex Calculator

4.5

4.5 | 2 ratings Rate this file 3 Downloads (last 30 days) File Size: 2.23 KB File ID: #12544

Hex Calculator

by Murphy O'Brien

 

05 Oct 2006 (Updated 10 Oct 2006)

Hex evaluation and calculator with logical and arithmetic operators

| Watch this File

File Information
Description

Evaluates the input character string as a hexadecimal expression and returns both hex and decimal outputs.
Allowed operators in precedence order are:
#(xor) &(and) |(or) ^(exponential) /(divide) *(times) -(minus) +(plus)
 
[OUTH,OUTD]=HEXCALC(EXPR)
evaluate the input expression and return both hex and decimal outputs.

HEXCALC(EXPR) with no output arguments prints both outputs

example:
hexcalc('F4*4-34/2*4-640*3+a#F2+3|A0')
prints out:
evaluates as FFFFF243 hex or -3517 decimal

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
06 Oct 2006 John D'Errico

Its hexcellent.

A very minor point, that the help should specify that the input expression is a character string, as is the hex output result, whereas the decimal output is a double variable. This is made fairly obvious by the examples so no foul here.

A point to note is that hexcalc operates on integers. But when the result is not integral, something interesting happens.

>> hexcalc('a/3')
evaluates as 3 hex or 3.33333 decimal

Things get slightly more interesting here:

>> hexcalc('a/3*3')
evaluates as 1 hex or 1.11111 decimal

Yes, this shows that the standard Matlab order of operations is not followed. So beware.

Then I tried to force hexcalc to change its order of operations, only to see that parentheses are not allowed.

>> hexcalc('(a/3)*3')
??? Error using ==> hexcalc
brackets are not allowed

Not bad otherwise.

12 Oct 2006 lijo joy

this is good. forgot to rate it.

Please login to add a comment or rating.
Updates
10 Oct 2006

Taking John's excellent review on board, changed precedence to more usual divide before multiply. Also changed help a little. Might get around to adding brackets some day if file proves popular.

Tag Activity for this File
Tag Applied By Date/Time
hex calculator hexadecimal Murphy O'Brien 22 Oct 2008 08:42:50

Contact us at files@mathworks.com