C
- voluntas
- @ignis_fatuus
- ブン
- @Linda_pp
- 清楚なC++メイドBOT
- @tzik_tack
- 長谷川一輝
- wraith13
- @jj1bdx
- @cpp_akira
- 安藤敏彦
- @srz_zumix
- Siv3D
- @okdshin
- @hnokx
- @ishidakei
- @take_cheeze
- TAKEI Yuya
- @mumumu
- I (@wx257osn2)
- Tommy6
- わたやん
- @KorekaraSEDB
- @kariya_mitsuru
- @ciniml
- @beam2d
- @grafi_tt
- @nekketsuuu
- LouiS0616
- @volanja
- 大鎌広
- むてら
- ガチKGB
- 三重野賢人
x
52
1
2
3
4
// #include "base16_decoding_table.h"5
6
unsigned char base16_decoding_table1[256] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,0,8
10,11,12,13,14,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,11,12,13,14,15,9
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};13
14
/* the resulting binary string is half the size of the input hex string15
* because every two hex characters map to one byte */16
17
int main(int argc, char **argv){18
19
int TESTDATALEN=strlen(( char*) argv[1]);20
21
//unsigned char result[TESTDATALEN/2];22
char *result=malloc((TESTDATALEN/2)+1);23
*result='\0';24
25
26
size_t i;27
char cur;28
unsigned char val;29
30
for (i = 0; i < TESTDATALEN; i++) {31
cur = (char) argv[1][i];32
33
val = base16_decoding_table1[(int)cur];34
35
/* even characters are the first half, odd characters the second half36
* of the current output byte */37
if (i%2 == 0) {38
result[i/2] = val << 4;39
} else {40
result[i/2] |= val;41
}42
}43
result[(TESTDATALEN/2)] = '\0';44
45
printf ("Binary value: %s\n", result);46
47
free(result);48
49
return 0;50
51
}52
$ gcc prog.c -Wall -Wextra -std=gnu11
Start
prog.c: In function 'main':
prog.c:30:21: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
30 | for (i = 0; i < TESTDATALEN; i++) {
| ^
prog.c:17:16: warning: unused parameter 'argc' [-Wunused-parameter]
17 | int main(int argc, char **argv){
| ~~~~^~~~
Binary value: #Eg4Vx:K^o|-
0
Finish