下面的一段代码实现了使用位运算将小写字母再转化为大写的操作。其原理如下
故将英文字母转化为小写字母的算法为:
字母 | 0x20 = 小写字母
如果要将英文字母转化为大写字母,则:
字母 & 0xdf(二进制的1101 1111) = 大写字母
;Uppercase Conversion
;This program tests the Str_ucase procedure,which converts
;the letters in a string to uppercase.
include irvine32.inc
Str_ucase PROTO,
pString:PTR BYTE
.data
string_1 BYTE "abcdef",0
string_2 BYTE "aB234dEfg",0
string_3 BYTE 0
.code
main PROC
call Clrscr
invoke Str_ucase,addr string_1
mov edx,offset string_1
call WriteString
call Crlf
invoke Str_ucase,addr string_2
mov edx,offset string_1
call WriteString
call Crlf
invoke Str_ucase,addr string_3
mov edx,offset string_1
call WriteString
call Crlf
call WaitMsg
exit
main endp
end main
本文介绍了一种使用位运算技巧将英文小写字母转换为大写字母的方法。通过应用位与运算,代码能够高效地完成字符串中字母的大小写转换。示例代码展示了如何在不同字符串上应用这一算法。
1271

被折叠的 条评论
为什么被折叠?



