unsigned

unsigned becomes signed in if-statement comparisons?

独自空忆成欢 提交于 2019-11-29 06:54:43
I have searched this site for an answer and found many responses to unsigned/signed comparison but this problem is that only unsigned parameters are compared but still it works funny. The problem with the following code is that the first if -statment does not happen ("hello") where as the second ("world") does. This I have interpreted as the calculation that is done inside the if -statment generates a negative number but the exact same calculation done with the result saved to a variables does not (even though the result is being saved to a signed variable). The compiler used is gcc 4.4.

第二季-专题13-NandFlash变硬盘

∥☆過路亽.° 提交于 2019-11-29 04:18:11
专题3-NandFlash变硬盘 第1课-NandFlash原理解析 角色分析 在电脑中有硬盘,它是用来存储文件的。嵌入式系统是防电脑的系统,在嵌入式系统中,NandFlash就相当于硬盘的存在。 NandFlash的分类 2.1 根据物理结构上的区别,NandFlash主要分为如下两类: l SLC(Single Level Cell):单层式存储 l MLC(Muti Level Cell):多层式存储 SLC在存储格上只存一位数据,而MLC则存放两位数据 2.2 MLC对比SLC 价格:由于MLC采用了更高密度的存储方式,因此同容量的MLC价格上远低于SLC 访问速度:SLC的访问速度一般要比MLC快3倍以上 使用寿命:SLC能进行10万次的擦写,MLC能进行1万次 功耗:MLC功耗比SLC高15%左右 访问方式 (1) 对比内存与NandFlash的编址区别 CPU内部有NandFlash控制,负责NandFlash与CPU之间的通信,通过地址、命令和数据三个寄存器来完成这一系列的通信。 (2) NandFlash地址构成 一块NandFlash划分成多个Block,一个Block划分成多个page,一个page划分成两个部分。 (3) 信号引脚 CLE(Command Latch Enable): 命令锁存允许 ALE(Address Lactch Enable):

Why compiler is not giving error when signed value is assigned to unsigned integer? - C++

邮差的信 提交于 2019-11-29 03:12:32
I know unsigned int can't hold negative values. But the following code compiles without any errors/warnings. unsigned int a = -10; When I print the variable a , I get a wrong value printed. If unsigned variables can't hold signed values, why do compilers allow them to compile without giving any error/warning? Any thoughts? Edit Compiler : VC++ compiler Solution Need to use the warning level 4. Microsoft Visual C++: warning C4245: 'initializing' : conversion from 'int' to 'unsigned int', signed/unsigned mismatch On warning level 4. G++ Gives me the warning: warning: converting of negative value

windows下用OPENGL播放视频 -采用纹理显示

吃可爱长大的小学妹 提交于 2019-11-29 02:46:26
采用OPENGL纹理显示视频 OPENGL 显示视频2种 1.直接纹理显示 在1.0 就支持 2.基于可编程(着色器)纹理显示 1.5后支持 这个之前的文章介绍过 有一点要记住 在windows上显示视频,窗口DC只支持RGB,所以如果是YUV 一定要转换RGB 在1.5后着色器可编程转换。1.5之前的自己转换 这里介绍直接纹理显示视频 1.设置显示窗口DC参数,创建OPENGL上下文,纹理对象及参数 2.显示视频 a.将YUV 转换 RGB b.将数据拷贝到纹理glTexSubImage2D c.通过glBegin glTexCoord2f glVertex2f 绘制纹理数据 d.显示SwapBuffers(hGLDC) 3.释放资源 OPENGL上下文,纹理资源 //代码头文件 OpenGLDisplay5.h #pragma once #include "GL/glew.h" class OpenGLDisplay5 { public: OpenGLDisplay5(void); ~OpenGLDisplay5(void){}; public: int init(HWND hwnd,int w,int h); void fini(); int display(uint8_t* Y,uint8_t* U,uint8_t* V); private: void

Why would we use addiu instead of addi?

余生颓废 提交于 2019-11-29 02:35:58
In MIPS assembly, what is the benefit of using addiu over addi ? Isn't addiu unsigned (and will ruin our calculations?) and will ruin our calculations No, MIPS uses two's complement , hence the same instruction for addition/subtraction can be used for both signed and unsigned operations. There's no difference in the result. That's also true for bitwise instructions, non-widening multiplication and many other operations. See Which arithmetic operations are the same on unsigned and two's complement signed numbers? Difference between signed and unsigned on bitwise operations The only difference

我是如何学习写一个操作系统(八):内存管理和段页机制

最后都变了- 提交于 2019-11-29 00:48:30
前言 多进程和内存管理是紧密相连的两个模块,因为运行进程也就是从内存中取指执行,创建进程首先要将程序和数据装入内存。将用户原程序变成可在内存中执行的程序,而这就涉及到了内存管理。 内存的装入 绝对装入。 在编译时,如果知道程序将驻留在内存的某个位置,编译程序将产生绝对地址的目标代码。绝对装入程序按照装入模块的地址,将程序和数据装入内存。装入模块被装入内存后,由于程序中的逻辑地址与实际地址完全相同,故不需对程序和数据的地址进行修改。 可重定位装入。 在多道程序环境下,多个目标模块的起始地址通常都是从0开始,程序中的其他地址都是相对于起始地址的,此时应采用可重定位装入方式。根据内存的当前情况,将装入模块装入到内存的适当位置。装入时对目标程序中指令和数据的修改过程称为重定位,地址变换通常是装入时一次完成,所以成为静态重定位。 其特点是在一个作业装入内存时,必须分配器要求的全部内存空间,如果没有足够的内存,就不能装入,此外一旦作业进入内存后,在整个运行期间,不能在内存中移动,也不能再申请内存空间。 动态运行时装入 也成为动态重定位,程序在内存中如果发生移动,就需要采用动态的装入方式。 动态运行时的装入程序在把装入模块装入内存后,并不立即把装入模块中的相对地址转换为绝对地址,而是把这种地址转换推迟到程序真正要执行时才进行。因此,装入内存后的所有地址均为相对地址

许可证加解密

£可爱£侵袭症+ 提交于 2019-11-29 00:40:33
license服务器 根据菜单选项制作明文,包括了: 序列号:基于硬件特殊mac计算 signature:文件利用公钥计算 功能选项:url过滤,病毒扫描,云查杀等一些特有服务功能 pem:.pem这种文件就是一个X.509的数字证书,里面有用户的公钥等信息 加解密过程: 文件数据(4的倍数检查)->EVP_DecodeBlock(4:3)->license_enc(通过key)->buff 1、base64编解码 license文件是base64编码,需要转换为base编码 base64是将字符的assic码,转换为都在0-64的可见范围内,不会有特殊符号“:”等影响数据头,从而影响解析 字符8位只取低6位,高补0,也就是3个8位变4个6位。 这里有可能会末尾signature多“=”,由于之前的license文件的位数不是6的倍数 解码时候需要删除=右边数据 Base64编码函数 Void EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n); 功能:进行Base64数据编码, 适用于小量数据。 参数:t:[OUT]编码后的数据。F:[IN]待编码的数据。N:[IN]待编码数据的长度 返回值:编码后的数据长度。 Base64解码函数 Void EVP_DecodeBlock(unsigned char

C++的四种转换(const_cast、static_cast、dynamic_cast、reinterpreter_cast)

≯℡__Kan透↙ 提交于 2019-11-29 00:17:27
static_cast 相当于C语言中的强制转换:(类型)表达式或类型(表达式),用于各种隐式转换 非const转const、void*转指针、int和char相互转换 用于基类和子类之间的 指针和引用 转换,非指针直接报错 向上转化是安全的,如果向下转能(指针或引用)成功但是不安全,结果未知; dynamic_cast 用于动态类型转换。只能用于含有 虚函数 的类,必须用在多态体系种,用于类层次间的向上和向下转化。只能转指针或引用。向下转化时,如果是非法的对于指针返回NULL,对于引用抛异常。 在进行下行转换时,dynamic_cast具有类型检查的功能,比static_cast更安全。 如果没有virtual方法进行下行转换(指针或引用)会直接报错 const_cast 常量指针被转化成非常量的指针,并且仍然指向原来的对象; 常量引用被转换成非常量的引用,并且仍然指向原来的对象; const_cast一般用于修改底指针。如const char *p形式。 const int a=10; int *p=const_cast<int*>(&a); //p和a指向同一块内存地址 *p = 100; //修改*p,但a=10,*p=100 reinterpret_cast (重解释转换)几乎什么都可以转,比如将int转指针,可能会出问题,尽量少用;随意的转换编译都会通过

what happens when i mix signed and unsigned types ?

為{幸葍}努か 提交于 2019-11-28 23:20:35
I'm studying the C++ language and i have some doubt about type conversion, could you explain me what happens in an expression like this : unsigned int u = 10; int a = -42; std::cout << u - a << std::endl; Here i know that the result will be 52 if i apply the rules when we have two mathematical operators.But i wonder what happens when the compiler to convert a to an unsigned value creates a temporary of unsigned type, what happens after ? The expression now should be 10 -4294967254. In simple terms, if you mix types of the same rank (in the sequence of int , long int , long long int ), the

Unsigned and Signed Values in C (Output)

橙三吉。 提交于 2019-11-28 21:56:36
signed int x = -5; unsigned int y = x; What is the value of y ? How is this so? kennytm It depends on the maximum value of the unsigned int . Typically, a unsigned int is 32-bit long, so the UINT_MAX is 2 32 − 1. The C standard (§6.3.1.3/2) requires a signed → unsigned conversion be performed as Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type. Thus y = x + ((2 32 − 1) + 1) = 2 32 − 5 = 4294967291. In a 2's complement platform