Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: quick way to decipher 4-char codes




On Nov 23, 2007, at 10:43 AM, James Hober wrote:

Ivan C Myrvold wrote:

The result is printed out with a NSLog:

2007-11-23 07:33:32.822 Tansa[8848:10b] SelectedScriptMenu dict: {
     1886282093 = Mail;
     1668116085 = 5;
}

As, Christiaan pointed out, 1886282093 and 1668116085 are four-char codes.


Tip: A quick way to decipher them is to paste them into Calculator, set Calculator to Programmer using the View menu and press the ASCII button.

If you like'd MacsBug and don't mind java....

#1886282093
  $706e616d  #1886282093 #1886282093  'pnam'

#1668116085
  $636d6e75  #1668116085 #1668116085  'cmnu'

# indicates decimal entry to disambiguate from default hex entry.

/**
MacsBug style number display and simple (hex/)integer calculation
Numbers assumed to default to hex, # must be prefixed for decimal, 10 = #16,
#-15 for -15.
Calculations are strictly left to right with no precedence 2 + 3 * 4 = 20 not 14
**/

public class mbeval {


public static void main(String [] args) {
int num;
char op = ' ';

if (args.length == 0) {
System.out.println("mbeval: No input");
return;
}

num = getNum(args[0]);

if (args.length > 1) {
for (int i=1; i<args.length;) {
try { op = getOp(args[i++]); }
catch (IllegalArgumentException iae) {
System.out.println("mbeval: [Invalid Operation] ");
return;
}
if (i > args.length) {
System.out.println("mbeval: [Incomplete expression] ");
}

num = doop(num,op,getNum(args[i++]));
}
}

print(num);
}

static char getOp(String s) {
if (s.length() > 1) throw new IllegalArgumentException(s);
char c = s.charAt(0);
if (c != '+' && c != '-' && c != '*' && c != '/') throw new IllegalArgumentException(s);
return c;
}

static int doop(int num, char op, int operand) {
if (op == '+') return num + operand;
if (op == '-') return num - operand;
if (op == '*') return num * operand;
return num / operand;
}

static int getNum(String s) {
int num = 0, radix = 10;
try {
if (!s.startsWith("#")) radix = 16;
else s = s.substring(1); // Strip the # prefix
return Integer.parseInt(s,radix);
}
catch (NumberFormatException nfe) {}
return num;
}

static void print(int num) {
try {
System.out.print(" $" + Integer.toHexString(num) + " ");
System.out.print("#" + Math.abs(num) + " #" + num + " ");
byte [] b = new byte[4];
pokeInt(b,0,num);
System.out.println("'" + (char)b[0] + (char)b[1] + (char)b[2] + (char)b[3] + "'");
}
catch (Exception ex) { ex.printStackTrace(); }
}

static void pokeInt(byte [] a, int index, int i)
{
a[index] = (byte)(i >> 24);
a[index +1] = (byte)(i << 8 >> 24);
a[index + 2] = (byte)(i << 16 >> 24);
a[index + 3] = (byte)(i << 24 >> 24);
}
}


Mike Hall        hallmike at att dot net
http://www.geocities.com/mik3hall
http://sourceforge.net/projects/macnative



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-implementors mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-implementors/email@hidden

This email sent to email@hidden
References: 
 >quick way to decipher 4-char codes (From: James Hober <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.