forked from ebecheto/Skill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitString2hexa.il
33 lines (28 loc) · 1.21 KB
/
bitString2hexa.il
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
;; copyleft ebecheto
ineed('abBinaryStrToInt)
defun( bitString2hexa (@optional (bitstr "10111000111011100011") (noquote nil))
let((r739 x739)
r739=reverse(parseString(bitstr ""));=> ("1" "1" "0" "0" "0" "1" "1" "1" "0" "1")
x739='()
while(r739
x739=append(x739 list(
sprintf(nil "%02x" abBinaryStrToInt(apply('strcat reverse(list(
car(r739) nth(1 r739)||"" nth(2 r739)||"" nth(3 r739)||""
nth(4 r739)||"" nth(5 r739)||"" nth(6 r739)||"" nth(7 r739)||""
)))))
))
r739=nthcdr(8 r739)
)
when(noquote foreach(mapcar x reverse(x739) printf("%s " x)))
reverse(x739) ;=> ("2" "e3")
))
printf("bitString2hexa();<= defaulf : convertit une string de bit en hexa \"10111000111011100011\"\n")
printf("bitString2hexa(%L t);<= fait aussi un printf (sans les quotes)\n" "10111000111011100011")
printf("bitString2hexa(strcat(%L %L) t);<= fait aussi un printf (sans les quotes)\n" "1011100011" "1011100011")
printf("hex=apply('strcat cons(\"0x\" bitString2hexa()));=> \"0x0b8ee3\"\n")
printf("sprintf(nil \"%%d\" evalstring(hex));=> \"757475\"\n")
; apply('strcat cons("0x" bitString2hexa())) ;=> "0x0b8ee3"
;; hex="0x0b8ee3"
;; sprintf(nil "%02x" evalstring(hex))
;; sprintf(nil "%x" evalstring(hex))
;; sprintf(nil "%d" evalstring(hex));=> "757475"