본문 바로가기

Android/이론

[Java/kotlin] Hex String의 Int 변환

728x90
반응형
SMALL

 

16bit Hex String to Signed Int

  • java
int i = (short) Integer.parseInt("FFFF", 16);
  • kotlin
val i: Short = Integer.parseInt("FFFF",16).toShort()

 

16bit Hex String to Unsigned Int

  • java
int i = Integer.parseUnsignedInt("FFFF", 16);  
  • kotlin
val i = "FFFF".toLong(16)

 

 

32bit Hex String to Signed Int

  • java
int x = (int)Long.parseLong("FFFFFFFC", 16); // x = -4
  • kotlin
val x = "FFFFFFFC".toLong(16).toInt() // x = -4

 

 

 

728x90
반응형
LIST