您的批评和鼓励都是我把编程无限办好的动力! 您编程时遇到困难,或遇到不顺心的事想发发牢骚尽管到这里来吧! 虽然本网力求全面,但也不能包罗万象,这些我筛选出的优秀网站连接就是对本站最好的补充! 学习编程当然也离不开书本了,这里收集大量编程书籍! 编程无限之源码超市,这里收集的代码令你意想不到的全面! 欢迎光临编程网校,这里专门收集VB/CB入门文章及技术文章! 欢迎光临编程无限!
     
       
 
当前位置:中文资料 >> 字符串
如何转换C代码中的高字和低字
  资料类型: 字符串 上传时间: 2001-02-21 阅读次数: 2011



如何转换C代码中的高字和低字
HiWords and LoWords from Long Values

 When translating C code to VB, you quite often come across the HiWord and LoWord
operators, used to pack two integers into a long value. A simple translation of
HiWord code will run into difficulties when unsigned integer arithmetic is being
used in the C code and the highest bit of the long value can be set. Since VB doesn't
support unsigned arithmetic we have to strip out the high bit and add it back again
later to avoid overflows and misleading results.

  当把C代码翻译到VB时,你经常会遇到高字和低字的操作,通常是把两个整型值合成一个长整型。当在C代码中使用了无符号整型,这最高一位是可以被设置的,因此简单的直接转换高字将会遇到困难。由于VB不支持无符号算术符,我们只好剥去这最高一位,在稍后再把它加回来,以避免溢出和错误的结果。(WXJ_Lake 译)

开始一个新工程,增添一个标准模块。把以下代码写入模块:
Start a new project then add a module. Add the following code to the module:

Public Property Get LoWord(ByRef lThis As Long) As Long
  LoWord = (lThis And &HFFFF&)
End Property

Public Property Let LoWord(ByRef lThis As Long, ByVal lLoWord As Long)
  lThis = lThis And Not &HFFFF& Or lLoWord
End Property

Public Property Get HiWord(ByRef lThis As Long) As Long
  If (lThis And &H80000000) = &H80000000 Then
   HiWord = ((lThis And &H7FFF0000) &H10000) Or &H8000&
  Else
   HiWord = (lThis And &HFFFF0000) &H10000
  End If
End Property

Public Property Let HiWord(ByRef lThis As Long, ByVal lHiWord As Long)
  If (lHiWord And &H8000&) = &H8000& Then
   lThis = lThis And Not &HFFFF0000 Or ((lHiWord And &H7FFF&) * &H10000) Or &H80000000
  Else
   lThis = lThis And Not &HFFFF0000 Or (lHiWord * &H10000)
  End If
End Property

推荐给朋友 点 评( 0 ) 返回前页 关闭此页
   
  本类最热文章排名:
  1.字符串中文的问题
2.字符串中包含双引号
3.怎样把VC++代码转换成VB代码
4.如何使VB的网格控件具有输入功能
5.如何取得汉字的区位码?
6.如何由两个ASC码(区位码)复原成一个汉...
7.切分字符串
8.如何取得中英混合字符串的长度?
9.一些字符串操作的问题和回答
10.如何取得汉字的区位码
   
   
  评论:
 
 
 

 

关于本站 版权声明 联系方法
编程无限 V4.1 Copyright © 1999-2008 21code.com

京ICP备05006938号