存档

‘Computer’ 分类的存档

[整理]在C中操作int的连续某几位

2010年7月12日 Galaxy 1 条评论

翻同事的The C Programming Language 2th(C程序设计语言)和对应的习题解答The C Answer Book看到的。
实体书看得爽,但写文章还是得找电子版,英文的chm有,可惜习题解答没文字版……

The shift operators < < and >> perform left and right shifts of their left operand by the number of bit positions given by the right operand, which must be non-negative. Thus x < < 2 shifts the value of x by two positions, filling vacated bits with zero; this is equivalent to multiplication by 4. Right shifting an unsigned quantity always fits the vacated bits with zero. Right shifting a signed quantity will fill with bit signs (``arithmetic shift'') on some machines and with 0-bits (``logical shift'') on others.

The unary operator ~ yields the one’s complement of an integer; that is, it converts each 1-bit into a 0-bit and vice versa. For example

   x = x & ~077

sets the last six bits of x to zero. Note that x & ~077 is independent of word length, and is thus preferable to, for example, x & 0177700, which assumes that x is a 16-bit quantity. The portable form involves no extra cost, since ~077 is a constant expression that can be evaluated at compile time.
As an illustration of some of the bit operators, consider the function getbits(x,p,n) that returns the (right adjusted) n-bit field of x that begins at position p. We assume that bit position 0 is at the right end and that n and p are sensible positive values. For example, getbits(x,4,3) returns the three bits in positions 4, 3 and 2, right-adjusted.

/* getbits:  get n bits from position p */
unsigned getbits(unsigned x, int p, int n)
{
	return (x >> (p+1-n)) & ~(~0 < < n);
}

The expression x >> (p+1-n) moves the desired field to the right end of the word. ~0 is all 1-bits; shifting it left n positions with ~0< places zeros in the rightmost n bits; complementing that with ~ makes a mask with ones in the rightmost n bits.


Exercise 2-6. Write a function setbits(x,p,n,y) that returns x with the n bits that begin at position p set to the rightmost n bits of y, leaving the other bits unchanged.

unsigned setbits(unsigned x, int p, int n, unsigned y)
{
	return (x & ((~0 < < (p + 1)) | (~(~0 << (p + 1 - n))))) | ((y & ~(~0 << n)) << (p + 1 - n));
}

下面这个比较快:

unsigned setbits(unsigned x, int p, int n, unsigned y)
{
	return x & ~(~(~0 < < n)  << (p+1-n)) |
	      (y &   ~(~0 << n)) << (p+1-n));
}

阅读全文...

分类: C_CPP_CS 标签: ,

[ZT]DELL的VOSTRO1400笔记本电池针脚

2010年7月1日 Galaxy 1 条评论

http://nbbbs.zol.com.cn/37/21_365194.html
DELL的VOSTRO1400笔记本电池用作备用输出电源转成5V
DELL的VOSTRO1400笔记本电脑,经常带着出差,出差时手机又没电源充电,于是做了一个接头,将笔记本电池作为备用电源,转成5V输出。

笔记本电池型号是WW116,11.1V,56Wh,有9个脚,针脚定义是从网上得来的。

只要将ctl脚与负极-脚短路,电池就会有电压输出了!再接一个7805,就可以作为应急供电了。自已用铜片焊在一个废电路板上,就成了。铜片比较不好找。


阅读全文…

分类: Hardware, Software 标签: ,

SlickEdit 的破解

2010年7月1日 Galaxy 没有评论

据说,SlickEdit是目前最好的程序编辑器。虽然编辑器有SciTE,源码阅读有Source-Navigator,但目前还是SlickEdit比较适合开发大程序。小程序当然是EditPlus搞定。(刚发现EditPlus的矩形文字块是用Alt加鼠标左键拖动定义的……)

商业软件的话,当然得破解。某华人李某的博客不错,可以借鉴。

先说SlickEdit 2010 (15.0.x):

Linux版本

080784CD                 mov     eax, esi   改成  xor eax, eax

也就是 文件 slickedit/bin/vs 的偏移 0×304CD 处 的 89 F0 改成 33 C0

Windows版本

0040F750                 mov     eax, ebp  改成  xor eax,eax

也就是 文件 SlickEditV15.0.0\win\vs.exe 的偏移 0xEB50 处的 8B C5 改成 33 C0

跟SlickEdit 2009类似, 都是通过查找 |== NOT FOR RESALE ==| 这个字符串找到 适当的函数.

2010-5-23

SlickEdit 15.0.0.6 跟 SlickEdit 15.0.0.5 的可执行文件没有变化, 修改方法也一样

Build Date: May 07, 2010
SlickEdit v15.0.0.6 contains a few bug fixes for problems discovered in v15.0.0.5. If you are currently running SlickEdit v15.0.0.5 with hotfix_se1500_3_cumulative.zip installed (or any later cumulative hotfix), you do NOT need to install this new version of SlickEdit.

阅读全文…

分类: Software 标签: , ,

[ZT]GOOGLE GUIDE: Google Calculator Quick Reference

2010年6月21日 Galaxy 没有评论

http://www.googleguide.com/help/calculator.html
本地镜像

感觉要记的就是Currency (money):
23 USD in Euros
120 JPY to RMB

当然,也可以直接去官网点菜。
阅读全文…

分类: Other Softs 标签: , ,

[ZT]QTTabBar 1.5.0.0 for win7 – 资源管理器标签管理工具

2010年6月17日 Galaxy 没有评论

http://www.cnbeta.com/articles/112472.htm
http://qttabbar.sourceforge.net/

QTTabBar 1.5.0.0 for win7 – 资源管理器标签管理工具
ugmbbc发布于 2010-05-30 15:08:36

浏览器中的多标签(Tab)功能非常受欢迎,但是你有没有想过在资源管理器Windows Explorer中使用Tab方式来管理文件呢? 目前有一些多标签的文件管理器软件,但都是独立软件,操作习惯上不象使用windows默认的资源管理器,如果你想让默认的windows资源管理器加上多标签功能,那就快来使用QT TabBar吧!它会让你在Windows Explorer中使用Tab标签功能,让你工作时不再堆满文件夹窗口,而在使用过程中又保持原汁原味的资源管理器操作方法和习惯。
阅读全文…

分类: Windows 标签: , ,

[ZT]关于vista的aero效果

2010年6月15日 Galaxy 没有评论

http://beatricesmth.blog41.fc2.com/blog-entry-25.html

我不要这种充满了IT文的宅用blog啊~~(碎碎念)

总之这是今晚EP的结果。

vista的aero效果是使用所谓的桌面窗口管理器,也就是Desktop Window Manager(DWM)实现的,放狗以这个关键词一搜头条就是MSDN所以不用费神给连接了。

在默认情形下,DWM用aero的半透明效果渲染程序窗口的非客户区(non-client,嘛反正windows下面搞过点界面的都能明白吧),然后它也提供了两个API:DwmExtendFrameIntoClientArea和EnableBlurBehind来允许把半透明效果应用到客户区域。就这么简单。

真的么…………抱歉,这是孔明的陷阱。

如果你只是简单地把API应用到原有的程序上面的话,结果只有“惨不忍睹”四字……
阅读全文…

分类: Programming 标签: , ,

[ZT]关于一些特殊浮点数

2010年6月13日 Galaxy 没有评论

http://live.aulddays.com/tech/10/double-float-ind-nan-inf/
打印浮点数输出 1.#IND 1.#INF nan inf 等解决
2010-03-11 11:24:34 旧日重来

进行浮点数编程时,如果没有注意,常常会出现输出类似 1.#IND, 1.#INF 或者 nan, inf 之类奇怪的输出。这通常隐含了浮点数操作的异常。
阅读全文…

分类: C_CPP_CS 标签: ,

[ZT]32 位 Windows 7 / Vista 启用 PAE 后仍然不支持 4G 内存原因分析

2010年6月13日 Galaxy 没有评论

去年转了篇老外讲理论的,现在在转篇国人讲理论和实践的(当然,理论是一样的……):
http://live.aulddays.com/tech/09/vista-ram-pae/
32 位 Windows 7 / Vista 启用 PAE 后仍然不支持 4G 内存原因分析
2009-03-09 19:20:45 旧日重来
2009-12-02:更新 Windows 7 RTM 内核 Patch 地址。
阅读全文…

分类: Windows 标签: , ,
Locations of visitors to this page