| 27 | } |
| 28 | |
| 29 | public set(value: ICharacter | INumeric | string | number) { |
| 30 | if (typeof value === "string") { |
| 31 | // the input is interpreted as hexadecimal digits, the conversion stops at |
| 32 | // the first character which is not an uppercase hex digit |
| 33 | this.value = /^[0-9A-F]*/.exec(value)?.[0] || ""; |
| 34 | if (this.value.length % 2 === 1) { |
| 35 | this.value = this.value + "0"; |
| 36 | } |
| 37 | } else if (typeof value === "number") { |
| 38 | this.value = Math.round(value).toString(16).toUpperCase(); |
| 39 | if (this.value.length % 2 === 1) { |
| 40 | this.value = "0" + this.value; |
| 41 | } |
| 42 | } else { |
| 43 | let v = value.get(); |
| 44 | if (value instanceof Float) { |
| 45 | v = value.getRaw(); |
| 46 | this.set(v); |
| 47 | } else if (value instanceof Character) { |
| 48 | this.set(value.getTrimEnd()); |
| 49 | } else if (typeof v === "number") { |
| 50 | this.value = v.toString(16).toUpperCase(); |
| 51 | if (this.value.length % 2 === 1) { |
| 52 | this.value = "0" + this.value; |
| 53 | } |
| 54 | } else { |
| 55 | this.set(v); |
| 56 | } |
| 57 | } |
| 58 | return this; |
| 59 | } |
| 60 | |