Daily Archives: June 28, 2010

Know some hashcodes


Some of the hashcodes of interest’s are in java wrappers

Boolean – hashCode() – 1231 for ‘true’ and ‘1237’ for ‘false’
Integer – hashCode() – will return the primitive int value
Byte – hashCode() – primitive int value of the byte is returned as hashcode
Charater- hashCode() – primitive int value of the byte is returned as hashcode
Long – value of the following expression

(int)(this.longValue()^(this.longValue()>>>32))

Magic Numbers a glance


Ever wonder how files are identified correctly as jpeg, gif or even class file for that matter by the OS.

Its all magic.. 🙂

Magic numbers are those which are prefixed at the start of the file in ASCII code to identify the file format.

Some of the common magic numbers are

Class bytecode starts with hex CAFEBABE
GIF image files have ‘GIF89a‘ (47 49 46 38 39 61) or ‘GIF87a‘ (47 49 46 38 37 61)
JPEG image files begin with ‘FF D8‘ and end with ‘FF D9'
PNG image files begin with “\211 P N G \r \n 32 \n” (89 50 4E 47 0D 0A 1A 0A)
ZIP files begin with ‘PK‘ (50 4B)
PDF files start with ‘%PDF‘ (25 50 44 46)