我有一个8位十六进制数,格式为 aarrggbb 。我需要将其转换为 rrggbbaa 格式和相反的方式。例如:
ARGB格式
#FFFF2323
我需要的是RGBA格式
#FF2323FF
ARGB格式
#FFFF2323
我需要的是RGBA格式
#FF2323FF
#FF123456
,
let x = '#FF123456';
console.log(x.replace(/#(..)(......)/, '#$2$1'));
let x = 0xFF123456
console.log(`#${(x & 0x0FFFFFF).toString(16).padStart(6, '0')}${(x >>> 24).toString(16).padStart(2, '0')}`);
您只需要将a[1]和a[2]移动到结尾即可。
var a = "#AABBCCDD";
var b = "#"+a.slice(3,9)+a[1]+a[2];
'#FFFF2323'.replace(/#(..)(......)/, '#$2$1')
。 - Jaromanda X