-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhex.pipe.ts
67 lines (60 loc) · 961 Bytes
/
hex.pipe.ts
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
import { Pipe,PipeTransform } from '@angular/core';
@Pipe ({ name:'tohex' })
export class tohex implements PipeTransform{
transform(rgb: number) : string {
let arg = rgb;
let hex='',y='';
let x=0;
do{
x = Math.floor(arg/16);
let rem = arg % 16 ;
arg = Math.floor(arg/16);
if(rem <= 9){
y+=rem;
}
else if( rem>9 && rem<13 ){
switch(rem){
case 10:{
y+='a';
break;
}
case 11:{
y+='b';
break;
}
case 12:{
y+='c';
break;
}
default:
//do nothing
}
}
else{
switch(rem){
case 13:{
y+='d';
break;
}
case 14:{
y+='e';
break;
}
case 15:{
y+='f';
break
}
default:
//do nothing
}
}
}while(x!=0);
if (y.length==1) {
y+='0';
}
for (var j = y.length - 1; j >= 0; j--) {
hex+=y[j];
}
return hex;
}
}