#include<stdio.h> int main() { unsigned char a,b,c; a =0x3; b= a|0x8; c=b<<1; printf("%d %d\n",b,c); return 0; }
时间: 2024-03-23 09:36:32 浏览: 104
这段代码中定义了三个无符号字符变量a、b、c,a被赋值为0x3,b被赋值为a按位或上0x8的结果,即二进制的0011 | 1000 = 1011,转为十进制为11。c被赋值为b左移一位的结果,即二进制的1011 << 1 = 10110,转为十进制为22。最后打印出b和c的十进制值,即11和22。输出结果为:
```
11 22
```
相关问题
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/socket.h> #include <netinet/ip.h> #define PORT 9090 /* Changing this size will change the layout of the stack. * We have added 2 dummy arrays: in main() and myprintf(). * Instructors can change this value each year, so students * won’t be able to use the solutions from the past. * Suggested value: between 0 and 300 */ #ifndef DUMMY_SIZE #define DUMMY_SIZE 100 #endif char *secret = "A secret message\n"; unsigned int target = 0x11223344; void myprintf(char *msg) { uintptr_t framep; // Copy the ebp value into framep, and print it out asm("movl %%ebp, %0" : "=r"(framep)); printf("The ebp value inside myprintf() is: 0x%.8x\n", framep); /* Change the size of the dummy array to randomize the parameters for this lab. Need to use the array at least once */ char dummy[DUMMY_SIZE]; memset(dummy, 0, DUMMY_SIZE); // This line has a format string vulnerability printf(msg); printf("The value of the ’target’ variable (after): 0x%.8x\n", target); }
这段代码存在一个格式化字符串漏洞,容易受到攻击者的利用。攻击者可以通过特殊的格式化字符串来读取或写入内存中的任意位置。具体来说,攻击者可以在传递给myprintf()函数的字符串中添加%c或%s等特殊字符,来读取内存中的任意位置。攻击者也可以使用%hn或%n等格式化字符串,来将值写入内存中的任意位置。例如,攻击者可以使用以下格式化字符串来将0x11223344写入target变量的地址0x0804a028处:
./vulnerable $(python -c "print('\x28\xa0\x04\x08' + '%4c%hn'*2)")
#include<REG52.H> #include<stdio.h> #include <intrins.h> sbit Trig=P2^0; sbit Echo=P2^1;超声模块测距代码补全
`#include<REG52.H>`是一段头文件的引用,代表使用了基于Intel 8051的单片机开发环境。`<stdio.h>`是标准输入输出头文件的引用。`<intrins.h>`是用于特殊函数的头文件引用。
以下是超声模块测距的代码补全:
```
#include<REG52.H>
#include<stdio.h>
#include <intrins.h>
sbit Trig=P2^0;
sbit Echo=P2^1;
void delay(unsigned int us) //延时函数
{
while(us--);
}
unsigned char read_distance() //读取距离函数
{
unsigned char distance;
Trig = 0; //初始化
delay(2);
Trig = 1; //触发测量
delay(10);
Trig = 0; //停止测量
while(!Echo); //等待Echo为高电平
TH0 = 0;
TL0 = 0; //清零计时器
while(Echo); //等待Echo为低电平
distance = (unsigned char)(TH0*256+TL0)/58.0; //计算距离
return distance;
}
void main()
{
unsigned char distance;
TMOD |= 0x01; //设置为定时器0,工作方式1
while(1)
{
distance = read_distance(); //读取距离
printf("The distance is %d cm\n",distance); //打印距离
delay(500); //延时500ms
}
}
```
阅读全文