riku
2019-09-15 4d44ed185203088052b10a8d1e3526fcbbc88331
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
package com.flightfeather.obd
 
import org.junit.Test
import java.nio.charset.Charset
import java.text.SimpleDateFormat
import java.util.*
 
/**
 * @author riku
 * Date: 2019/9/12
 */
class Test {
 
    @Test
    fun foo1() {
        val b = ByteArray(20) {8}
        println(b[18])
    }
 
    @Test
    fun foo2() {
        val b = ByteArray(1){97}
        val s = "a"
        println()
    }
 
    @Test
    fun foo3() {
        val hexNum = "ff"
        val length = hexNum.toInt(16)
        println(length)
    }
 
    @Test
    fun foo4() {
        val h = "0101"
        val byte = 0xff
        val b = h.toInt(16)
        println(b)
    }
 
    @Test
    fun foo5() {
        val s = "23 23 30 30 30 30 30 35 33 31 36 30 38 30 31 30 35 33 36"
        val sb = StringBuilder()
        val ascii = s.split(" ")
        ascii.forEach {
            sb.append(it.toIntOrNull(16)?.toChar())
        }
        println(sb.toString())
    }
 
    @Test
    fun foo6() {
        val cal  = Calendar.getInstance().apply {
            set(2019, 9, 15, 23, 16, 59)
        }
 
        println(SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.time))
    }
 
    @Test
    fun foo7() {
        val a = "0AAF".toIntOrNull(16)?.toString(2)
        println(a)
    }
 
    @Test
    fun foo8() {
        val byte = ByteArray(2)
        byte[0] = 0x23
        byte[1] = 0x23
 
        byte[0].toString(16)
    }
 
    @Test
    fun foo9() {
        val b = 128.toByte()
        var a = 0
        if (b < 0) {
            a = b + 256
        } else {
            a = b.toInt()
        }
        println(b.toString(16))
    }
}