BASIC4MCU | C언어 | C언어 | 졸면서 보는 C Tip - 11. HEXASC 변환
페이지 정보
작성자 키트 작성일2017-09-12 11:47 조회1,810회 댓글0건본문
11. HEXASC 변환
SMS 문자 등에 사용 되거나
CLCD 등에 16진 형태의 문자로 보고 싶은 경우에
int i=0x1234;
char buf[30];
sprintf(buf,"%x",i);
sprintf() 함수를 사용 해서 만들 수 있지만
그 기능만 함수로 만들고 싶으면 아래 처럼 만들면 됩니다.
char hex[]="0123456789ABCDEF";
char buf[]="00";
char data=0xA2;
buf[0]=hex[data>>0x04]; //'A'
buf[1]=hex[data &0x0F]; //'2'
반대로 HRXASC 문자열에서 정수로 변환 하는 경우에는
char str[] = "ff";
char hex;
if(str[0]<='9')hex=(str[0]-'0')<<4;
else hex=(str[0]-'A'+0xA)<<4;
if(str[1]<='9')hex|=str[1]-'0';
else hex|=str[1]-'A'+0xA;
HEXASC란
ASC 코드 중에서
16진수에 해당 하는 문자
'0'~'9' 와
'A'~'F' 를 말 합니다.
Table of ASCII Characters
binary MSN 0000 0001 0010 0011 0100 0101 0110 0111 LSN hex 0 1 2 3 4 5 6 7 0000 0 NUL 0
00DLE 16
10SP 32
200 48
30@ 64
40P 80
50` 96
60p 112
700001 1 SOH 1
01XON
(DC1)17
11! 33
211 49
31A 65
41Q 81
51a 97
61q 113
710010 2 STX 2
02DC2 18
12" 34
222 50
32B 66
42R 82
52b 98
62r 114
720011 3 ETX 3
03XOFF (DC2) 19
13# 35
233 51
33C 67
43S 83
53c 99
63s 115
730100 4 EOT 4
04DC4 20
14$ 36
244 52
34D 68
44T 84
54d 100
64t 116
740101 5 ENQ 5
05NAK 21
15% 37
255 53
35E 69
45U 85
55e 101
65u 117
750110 6 ACK 6
06SYN 22
16& 38
266 54
36F 70
46V 86
56f 102
66v 118
760111 7 BEL 7
07ETB 23
17' 39
277 55
37G 71
47W 87
57g 103
67w 119
771000 8 BS 8
08CAN 24
18( 40
288 56
38H 72
48X 88
58h 104
68x 120
781001 9 HT 9
09EM 25
19) 41
299 57
39I 73
49Y 89
59i 105
69y 121
791010 A LF 10
0ASUB 26
1A* 42
2A: 58
3AJ 74
4AZ 90
5Aj 106
6Az 122
7A1011 B VT 11
0BESC 27
1B+ 43
2B; 59
3BK 75
4B[ 91
5Bk 107
6B{ 123
7B1100 C FF 12
0CFS 28
1C, 44
2C< 60
3CL 76
4C\ 92
5Cl 108
6C| 124
7C1101 D CR 13
0DGS 29
1D- 45
2D= 61
3DM 77
4D] 93
5Dm 109
6D} 125
7D1110 E SO 14
0ERS 30
1E. 46
2E> 62
3EN 78
4E^ 94
5En 110
6E~ 126
7E1111 F SI 15
0FUS 31
1F/ 47
2F? 63
3FO 79
4F_ 95
5Fo 111
6FDEL 127
7F
|
|
The values to the right of the ASCII character are that character's ASCII values in decimal and hexadecimal. The LSN column signifies the least significant nybble (4 bits) of the binary value, the MSN row is the most significant nybble of the binary value, thus the commercial-at (@) sign has an LSN of 0000 and an MSN of 0100, making 01000000. The second row and column show the LSN and MSN in their hexadecimal (base 16) values.
ASCII values 32 decimal to 126 decimal are printable ASCII characters.
The position of the Pound Sign (?/b>) varies significantly between different interpretations of the ASCII set. In older versions it can sometimes be found at 35 decimal, in place of the hash symbol (#), but is now more often found at 163 decimal in the extended ASCII set.
ASCII is used in almost all computer systems except for some IBM midrange and mainframe systems that use EBCDIC. A more detailed explanation for ASCII and EBCDIC can be found here.
http://www.dynamoo.com/technical/ascii.htm
댓글 0
조회수 1,810등록된 댓글이 없습니다.