Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
Lab002
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
CS Lab Group
实验项目模板
实验模板
Lab002
提交
e6b4f4e5
提交
e6b4f4e5
12月 13, 2018
创建
作者:
赵鹏翀
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init template
上级
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
201 行增加
和
0 行删除
+201
-0
.gitignore
.gitignore
+2
-0
Lab002.csproj
Lab002.csproj
+31
-0
Lab002.puo
Lab002.puo
+0
-0
console.c
console.c
+159
-0
console.h
console.h
+9
-0
没有找到文件。
.gitignore
0 → 100644
浏览文件 @
e6b4f4e5
/Debug
/Release
Lab002.csproj
0 → 100644
浏览文件 @
e6b4f4e5
<?xml version="1.0" encoding="gb2312"?>
<ASMProject
Version=
"1.00"
Name=
"Lab002"
TemplatePath=
"console(c)\Project"
ProjectID=
"7ea2146b-ee89-437e-aa2b-20e3a77bb32f"
IsSubmitWork=
"0"
>
<Configurations>
<Configuration
Name=
"Debug"
DebuggerFlavor=
"0"
>
<Tool
Name=
"PreBuildEventTool"
/>
<Tool
Name=
"CustomBuildTool"
/>
<Tool
Name=
"GCCCompilerTool"
PreprocessorDefinitions=
"_DEBUG"
GenerateDebugInformation=
"-1"
LanguageStandard=
"c99"
/>
<Tool
Name=
"PreLinkEventTool"
/>
<Tool
Name=
"GCCLinkerTool"
/>
<Tool
Name=
"PostBuildEventTool"
/>
</Configuration>
<Configuration
Name=
"Release"
DebuggerFlavor=
"0"
>
<Tool
Name=
"PreBuildEventTool"
/>
<Tool
Name=
"CustomBuildTool"
/>
<Tool
Name=
"GCCCompilerTool"
PreprocessorDefinitions=
"NDEBUG"
LanguageStandard=
"c99"
/>
<Tool
Name=
"PreLinkEventTool"
/>
<Tool
Name=
"GCCLinkerTool"
StripDebugInfo=
"-1"
/>
<Tool
Name=
"PostBuildEventTool"
/>
</Configuration>
</Configurations>
<Files>
<Filter
Name=
"ͷļ"
Filter=
"h;hpp;hxx"
>
<File
RelativePath=
".\console.h"
>
</File>
</Filter>
<Filter
Name=
"Դļ"
Filter=
"cpp;c;cc;cxx"
>
<File
RelativePath=
".\console.c"
>
</File>
</Filter>
</Files>
</ASMProject>
Lab002.puo
0 → 100644
浏览文件 @
e6b4f4e5
添加文件
console.c
0 → 100644
浏览文件 @
e6b4f4e5
#include "console.h"
// 位操作
int
lsbZero
(
int
x
)
{
//x右移一位再左移一位实现把最低有效位置0
x
=
x
>>
1
;
x
=
x
<<
1
;
return
x
;
}
int
getByteNot
(
int
x
,
int
n
)
{
//x第n个字节每位都和1异或实现取反
int
y
=
0xff
;
n
=
n
<<
3
;
y
=
y
<<
n
;
x
=
(
x
^
y
);
return
x
;
}
int
logicalAnd
(
int
x
,
int
y
)
{
//把x和y分别转化为逻辑的0和1,再相与
x
=
!
x
;
x
=
!
x
;
y
=
!
y
;
y
=
!
y
;
x
=
x
&
y
;
return
x
;
}
// ****************************************************************************
int
logicalOr
(
int
x
,
int
y
)
{
// 此处将代码补充完整
// 函数的功能是:把x和y分别转化为逻辑的0和1,再相或
return
0
;
}
int
getByteXor
(
int
x
,
int
y
,
int
n
)
{
// 此处将代码补充完整
// 函数的功能是:将x和y的第n个字节比较,若不同,则返回1;若相同,则返回0
return
0
;
}
int
rotateLeft
(
int
x
,
int
n
)
{
// 此处将代码补充完整
// 函数的功能是:将x循环左移n位
return
x
;
}
int
parityCheck
(
int
x
)
{
// 此处将代码补充完整
// 函数的功能是:若x有奇数个1,则返回1;否则,返回0
return
0
;
}
// ****************************************************************************
// 补码运算
int
absVal
(
int
x
)
{
//x最高位为0时就是x,最高位为1时是~x+1
int
y
=
x
>>
31
;
int
k
=
(
~
y
)
&
x
;
x
=
~
x
+
1
;
x
=
y
&
x
+
k
;
return
x
;
}
int
mul2OK
(
int
x
)
{
//把x第31位和30位分别和1做按位与,再异或,再和1异或
int
m
;
int
p
=
(
x
>>
31
)
&
0x1
;
int
q
=
(
x
>>
30
)
&
0x1
;
m
=
p
^
q
;
return
m
^
0x1
;
}
// ****************************************************************************
int
mult3div2
(
int
x
)
{
// 此处将代码补充完整
// 函数的功能是:计算(x*3)/2,朝零方向取整
return
x
;
}
int
subOK
(
int
x
,
int
y
)
{
// 此处将代码补充完整
// 函数的功能是:计算x–y,如果不溢出,则返回1,否则,返回0
return
0
;
}
// ****************************************************************************
int
main
()
{
// 调用位操作函数
printf
(
"调用位操作函数
\n
"
);
printf
(
"***************************************************************
\n
"
);
printf
(
"最低有效位(LSB)清零
\n
"
);
int
x
=
0
;
x
=
lsbZero
(
0x87654321
);
printf
(
"lsbZero(0x87654321) = 0x%x
\n\n
"
,
x
);
printf
(
"将x的第n个字节取反
\n
"
);
x
=
getByteNot
(
0x1234ff78
,
1
);
printf
(
"getByteNot(0x1234ff78,1) = 0x%x
\n\n
"
,
x
);
printf
(
"把x和y分别转化为逻辑的0和1,再相与
\n
"
);
x
=
logicalAnd
(
0x12345678
,
0
);
printf
(
"logicalAnd(0x12345678, 0) = %d
\n\n
"
,
x
);
printf
(
"把x和y分别转化为逻辑的0和1,再相或
\n
"
);
x
=
logicalOr
(
0x12345678
,
0
);
printf
(
"logicalOr(0x12345678, 0) = %d
\n\n
"
,
x
);
printf
(
"比较x和y的第n个字节,若不同,则返回1;若相同,则返回0
\n
"
);
x
=
getByteXor
(
0x12345678
,
0x87654321
,
1
);
printf
(
"getByteXor(0x12345678, 0x87654321, 1) = %d
\n\n
"
,
x
);
printf
(
"将x循环左移n位
\n
"
);
x
=
rotateLeft
(
0x87654321
,
4
);
printf
(
"rotateLeft(0x87654321,4) = 0x%x
\n\n
"
,
x
);
printf
(
"若x有奇数个1,则返回1;否则,返回0
\n
"
);
x
=
parityCheck
(
7
);
printf
(
"parityCheck(7) = %d
\n\n
"
,
x
);
// 调用补码运算函数
printf
(
"调用补码运算函数
\n
"
);
printf
(
"***************************************************************
\n
"
);
printf
(
"求绝对值
\n
"
);
x
=
absVal
(
-
123
);
printf
(
"absVal(-123) = %d
\n\n
"
,
x
);
printf
(
"计算2*x,如果不溢出,则返回1,否则,返回0
\n
"
);
x
=
mul2OK
(
0x80000000
);
printf
(
"mul2OK(0x80000000) = %d
\n\n
"
,
x
);
printf
(
"计算(x*3)/2,朝零方向取整
\n
"
);
x
=
mult3div2
(
-
9
);
printf
(
"mult3div2(-9) = %d
\n\n
"
,
x
);
printf
(
"计算x–y,如果不溢出,则返回1,否则,返回0
\n
"
);
x
=
subOK
(
0x80000000
,
0x70000000
);
printf
(
"subOK(0x80000000,0x70000000) = %d
\n\n
"
,
x
);
return
0
;
}
console.h
0 → 100644
浏览文件 @
e6b4f4e5
#ifndef _CONSOLE_H_
#define _CONSOLE_H_
#include <stdio.h>
/* TODO: 在此处引用程序需要的其他头文件 */
#endif
/* _CONSOLE_H_ */
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论