C언어 > 졸면서 보는 C Tip - 11. HEXASC 변환

TODAY1,090 TOTAL2,933,376
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


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
 
00
DLE
16  
10
SP
32  
20
0
48  
30
@
64  
40
P
80  
50
`
96  
60
p
112  
70
0001
1
SOH
 
01
XON  
(DC1)
17  
11
!
33  
21
1
49  
31
A
65  
41
Q
81  
51
a
97  
61
q
113  
71
0010
2
STX
 
02
DC2
18  
12
"
34  
22
2
50  
32
B
66  
42
R
82  
52
b
98  
62
r
114  
72
0011
3
ETX
 
03
XOFF (DC2)
19  
13
#
35  
23
3
51  
33
C
67  
43
S
83  
53
c
99  
63
s
115  
73
0100
4
EOT
 
04
DC4
20  
14
$
36  
24
4
52  
34
D
68  
44
T
84  
54
d
100  
64
t
116  
74
0101
5
ENQ
 
05
NAK
21  
15
%
37  
25
5
53  
35
E
69  
45
U
85  
55
e
101  
65
u
117  
75
0110
6
ACK
 
06
SYN
22  
16
&
38 
26
6
54  
36
F
70  
46
V
86  
56
f
102  
66
v
118  
76
0111
7
BEL
 
07
ETB
23  
17
'
39  
27
7
55  
37
G
71  
47
W
87  
57
g
103  
67
w
119  
77
1000
8
BS
 
08
CAN
24  
18
(
40  
28
8
56  
38
H
72  
48
X
88  
58
h
104  
68
x
120  
78
1001
9
HT
 
09
EM
25  
19
)
41  
29
9
57  
39
I
73  
49
Y
89  
59
i
105  
69
y
121  
79
1010
A
LF
10  
0A
SUB
26  
1A
*
42  
2A
:
58  
3A
J
74  
4A
Z
90  
5A
j
106  
6A
z
122  
7A
1011
B
VT
11  
0B
ESC
27  
1B
+
43  
2B
;
59  
3B
K
75  
4B
[
91  
5B
k
107  
6B
{
123  
7B
1100
C
FF
12  
0C
FS
28  
1C
,
44  
2C
<
60  
3C
L
76  
4C
\
92  
5C
l
108  
6C
|
124  
7C
1101
D
CR
13  
0D
GS
29  
1D
-
45  
2D
=
61  
3D
M
77  
4D
]
93  
5D
m
109  
6D
}
125  
7D
1110
E
SO
14  
0E
RS
30  
1E
.
46  
2E
>
62  
3E
N
78  
4E
^
94 
5E
n
110  
6E
~
126  
7E
1111
F
SI
15  
0F
US
31  
1F
/
47  
2F
?
63  
3F
O
79  
4F
_
95  
5F
o
111  
6F
DEL
127  
7F

 

 

Hex
Name
Description
00
NUL
Null ^@
01
SOH
Start Of Heading
02
STX
Start of TeXt
03
ETX
End of TeXt
04
EOT
End Of Transmission
05
ENQ
ENQuiry
06
ACK
ACKnowledge
07
BEL
BELl (beep) ^G
08
BS
BackSpace ^H
09
TAB
horizontal TAB ^I
0A
LF
Line Feed ^J
0B
VT
Vertical Tab
0C
FF
Form Feed ^L
0D
CR
Carriage Return
0E
SO
Shift Out
0F
SI
Shift In
Hex
Name
Description
10
DLE
Data Link Escape
11
XON
Xmit ON ^Q
12
DC2
Device Control 2
13
XOFF
Xmit OFF ^S
14
DC4
Device Control 4
15
NAK
Negative AcKnowledge
16
SYN
SYNchronous idle
17
ETB
End of Transmission Block
18
CAN
CANcel
19
EM
End of Medium
1A
SUB
SUBstitute
1B
ESC
ESCape ^[
1C
FS
File Separator
1D
GS
Group Separator
1E
RS
Record Separator
1F
US
Unit Separator


 

 

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

등록된 댓글이 없습니다.

C언어HOME > C언어 > 전체 목록

게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020
모바일버전으로보기