Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: Spasi (posted 2012-09-09 04:28:19, viewed 190 times)

1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96   97   98   99   100   101   102   103   104   105   106   107   108   109   110   111   112   113   114   115   116   117   118   119   120   121   122   123   124   125   126   127   128   129   130   131  
inline fun Byte.toHex() = this.toInt().and(0xFF).toHex()
inline fun Short.toHex() = this.toInt().and(0xFFFF).toHex()
inline fun Int.toHex() = Integer.toHexString(this).toUpperCase()
inline fun Long.toHex() = java.lang.Long.toHexString(this).toUpperCase()

inline fun Byte.inv() = this.toInt().inv().and(0xFF).toByte()
inline fun Short.inv() = this.toInt().inv().and(0xFFFF).toShort()

inline fun Long.get(index: Int) = (this ushr (index shl 3)).toByte()
inline fun Int.get(index: Int) = (this ushr (index shl 3)).toByte()
inline fun Short.get(index: Int) = this.toInt()[index]

val Short.b0: Byte get() = this[0]
val Short.b1: Byte get() = this[1]

val Short.lo: Byte get() = this[0]
val Short.hi: Byte get() = this[1]

val Int.b0: Byte get() = this[0]
val Int.b1: Byte get() = this[1]
val Int.b2: Byte get() = this[2]
val Int.b3: Byte get() = this[3]

val Int.lo: Short get() = (this and 0xFFFF).toShort()
val Int.hi: Short get() = (this ushr 16).toShort()

private inline fun makeShort(hi: Byte, lo: Byte) = ((hi.toInt() shl 8) or lo.toInt()).toShort()

val Int.even: Short get() = makeShort(b2, b0)
val Int.odd: Short get() = makeShort(b3, b1)

val Long.b0: Byte get() = this[0]
val Long.b1: Byte get() = this[1]
val Long.b2: Byte get() = this[2]
val Long.b3: Byte get() = this[3]
val Long.b4: Byte get() = this[4]
val Long.b5: Byte get() = this[5]
val Long.b6: Byte get() = this[6]
val Long.b7: Byte get() = this[7]

val Long.lo: Int get() = (this and 0xFFFFFFFF).toInt()
val Long.hi: Int get() = (this ushr 32).toInt()

private inline fun makeInt(b3: Byte, b2: Byte, b1: Byte, b0: Byte) =
   (b3.toInt().and(0xFF) shl 24) or
   (b2.toInt().and(0xFF) shl 16) or
   (b1.toInt().and(0xFF) shl 8) or
   (b0.toInt().and(0xFF) shl 0)

val Long.even: Int get() = makeInt(this[6], this[4], this[2], this[0])
val Long.odd: Int get() = makeInt(this[7], this[5], this[3], this[1])

inline fun Int.set(index: Int, value: Byte) = this.set(index, value.toInt())
inline fun Int.set(index: Int, value: Int): Int {
   val shift = index shl 3
   return this.merge(value shl shift, 0xFF shl shift)
}
inline fun Int.merge(other: Int, mask: Int) = this xor ((this xor other) and mask)

fun main(args: Array<String>) {
   fun Byte.printHex(msg: String) = println("$msg = ${toHex()}")
   fun Short.printHex(msg: String) = println("$msg = ${toHex()}")
   fun Int.printHex(msg: String) = println("$msg = ${toHex()}")
   fun Long.printHex(msg: String) = println("$msg = ${toHex()}")

   val x = 0x12345678

   x.printHex("x")

   x[3].printHex("x3")
   x[2].printHex("x2")
   x[1].printHex("x1")
   x[0].printHex("x0")

   x.b3.printHex("x.b3")
   x.b2.printHex("x.b2")
   x.b1.printHex("x.b1")
   x.b0.printHex("x.b0")

   println("---------")

   val b = 0xFF

   x.set(0, b).printHex("x")
   x.set(1, b).printHex("x")
   x.set(2, b).printHex("x")
   x.set(3, b).printHex("x")

   println("---------")

   x.even.printHex("x.even")
   x.odd.printHex("x.odd")
   x.hi.printHex("x.hi")
   x.lo.printHex("x.lo")

   val l = 0x1122334455667788

   l.printHex("\nl")
   l.even.printHex("l.even")
   l.even.lo.printHex("l.even.lo")
   l.even.lo.hi.printHex("l.even.lo.hi")

   /*
   OUTPUT:

   x = 12345678
   x3 = 12
   x2 = 34
   x1 = 56
   x0 = 78
   x.b3 = 12
   x.b2 = 34
   x.b1 = 56
   x.b0 = 78
   ---------
   x = 123456FF
   x = 1234FF78
   x = 12FF5678
   x = FF345678
   ---------
   x.even = 3478
   x.odd = 1256
   x.hi = 1234
   x.lo = 5678

   l = 1122334455667788
   l.even = 22446688
   l.even.lo = 6688
   l.even.lo.hi = 66
   */
}





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (42 views)
2014-04-15 18:08:23

BurntPizza (38 views)
2014-04-15 03:46:01

UprightPath (54 views)
2014-04-14 17:39:50

UprightPath (36 views)
2014-04-14 17:35:47

Porlus (53 views)
2014-04-14 15:48:38

tom_mai78101 (75 views)
2014-04-10 04:04:31

BurntPizza (134 views)
2014-04-08 23:06:04

tom_mai78101 (234 views)
2014-04-05 13:34:39

trollwarrior1 (195 views)
2014-04-04 12:06:45

CJLetsGame (203 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!