unsigned

Signed vs. unsigned integers for lengths/counts

人盡茶涼 提交于 2019-11-26 22:50:40
问题 For representing a length or count variable, is it better to use signed or unsigned integers? It seems to me that C++ STL tends to prefer unsigned ( std::size_t , like in std::vector::size(), instead C# BCL tends to prefer signed integers (like in ICollection.Count. Considering that a length or a count are non-negative integers, my intuition would choose unsigned ; but I fail to understand why the .NET designers chose signed integers. What is the best approach? What are the pros and cons of

Difference between unsigned and unsigned int in C

孤街醉人 提交于 2019-11-26 22:38:56
Could you please make it clear what the difference is between unsigned and unsigned int ? Maybe some example code would be helpful. unsigned is a modifier which can apply to any integral type ( char , short , int , long , etc.) but on its own it is identical to unsigned int . There is no difference. unsigned and unsigned int are both synonyms for the same type (the unsigned version of the int type). unsigned alone means unsigned int. You can also use unsigned char , etc. I have no idea what happens if you try unsigned double or unsigned float . Anybody know? unsigned indicates that it's

Keil 程序调试窗口

六眼飞鱼酱① 提交于 2019-11-26 22:36:12
一、程序调试时的常用窗口 Keil 软件在调试程序时提供了多个窗口,主要包括输出窗口(Output Windows)、观察 窗口(Watch&Call Statck Windows)、存储器窗口(Memory Window)、反汇编窗口(Dissambly Window)串行窗口(Serial Window)等。进入调试模式后,可以通过菜单 View 下的相应命 令打开或关闭这些窗口。 图 1 是输出窗口、观察窗口和存储器窗口,各窗口的大小可以使用鼠标调整。进入调试 程序后,输出窗口自动切换到 Command 页。该页用于输入调试命令和输出调试信息。对于 初学者,可以暂不学习调试命令的使用方法。 图 1 调试窗口(命令窗口、存储器窗口、观察窗口) 1 、存储器窗口 ? 存储器窗口中可以显示系统中各种内存中的值,通过在 Address 后的编缉框内输入“字 母:数字”即可显示相应内存值,其中字母可以是 C、D、I、X,分别代表代码存储空间、 直接寻址的片内存储空间、间接寻址的片内存储空间、扩展的外部 RAM 空间,数字代表想 要查看的地址。例如输入 D:0 即可观察到地址 0 开始的片内 RAM 单元值、键入 C:0 即 可显示从 0 开始的 ROM 单元中的值,即查看程序的二进制代码。该窗口的显示值可以以各 种形式显示,如十进制、十六进制、字符型等,改变显示方式的方法是点鼠标右键

Best way to convert a signed integer to an unsigned long?

落爺英雄遲暮 提交于 2019-11-26 21:59:04
For certain hash functions in Java it would be nice to see the value as an unsigned integer (e.g. for comparison to other implementations) but Java supports only signed types. We can convert a signed int to an "unsigned" long as such: public static final int BITS_PER_BYTE = 8; public static long getUnsignedInt(int x) { ByteBuffer buf = ByteBuffer.allocate(Long.SIZE / BITS_PER_BYTE); buf.putInt(Integer.SIZE / BITS_PER_BYTE, x); return buf.getLong(0); } getUnsignedInt(-1); // => 4294967295 However, this solution seems like overkill for what we're really doing. Is there a more efficient way to

Why doesn't C have unsigned floats?

梦想的初衷 提交于 2019-11-26 21:22:16
I know, the question seems to be strange. Programmers sometimes think too much. Please read on... In C I use signed and unsigned integers a lot. I like the fact that the compiler warns me if I do things like assigning a signed integer to an unsigned variable. I get warnings if I compare signed with unsigned integers and much much more. I like these warnings. They help me to keep my code correct. Why don't we have the same luxury for floats? A square-root will definitely never return a negative number. There are other places as well where a negative float value has no meaning. Perfect candidate

Unity3D资源管理架构

北城以北 提交于 2019-11-26 20:52:54
转载自 Unity3D资源管理架构 在Unity3D引擎中,场景资源文件(.unity)是以2进制格式存储的,但同时它也有一种基于文本的表现格式。可在Edit>Project Setting>Editor 中设置: 1.使用binary2text.exe(win下目录:Editor\Data\Tools)可将.unity文件转换成.txt文件,只需将.unity文件拖拽到binary2text.exe上即可生成.txt; 2.Bin2Text.unity为测试场景场景中只有一个名为“sakyaer”的空物体; 3.对应这样一个场景,它的文本格式使用YAML格式存储,信息表如下: 其中ClassID是Unity3D中类的序列编号,如:GameObject类ClassID=1,具体类的ID参照官方网 http://docs.unity3d.com/Manual/ClassIDReference.html ID项为随记分配给每个实例的唯一标识 资源文件使用m_作为前缀 其中m_GameObject (file 0 path 1163297905)表现transform对gameobject的从属关系 External References ID: 1 (ClassID: 29) SceneSettings m_ObjectHideFlags 0 (unsigned int) m

Why does “int[] is uint[] == true” in C#

余生长醉 提交于 2019-11-26 20:24:13
Can somebody clarify the C# is keyword please. In particular these 2 questions: Q1) line 5; Why does this return true? Q2) line 7; Why no cast exception? public void Test() { object intArray = new int[] { -100, -200 }; if (intArray is uint[]) //why does this return true? { uint[] uintArray = (uint[])intArray; //why no class cast exception? for (int x = 0; x < uintArray.Length; x++) { Console.Out.WriteLine(uintArray[x]); } } } MSDN's description does not clarify the situation. It states that is will return true if either of these conditions are met. (http://msdn.microsoft.com/en-us/library

difference between printing a memory address using %u and %d in C?

十年热恋 提交于 2019-11-26 20:15:01
问题 I reading a C book. To print out a memory address of a variable, sometimes the book uses: printf("%u\n",&n); Sometimes, the author wrote: printf("%d\n",&n); The result is always the same, but I do not understand the differences between the two (I know %u for unsigned). Can anyone elaborate on this, please? Thanks a lot. 回答1: %u treats the integer as unsigned, whereas %d treats the integer as signed. If the integer is between 0 an INT_MAX (which is 2 31 -1 on 32-bit systems), then the output

Unsigned keyword in C++

前提是你 提交于 2019-11-26 18:59:02
问题 Does the unsigned keyword default to a specific data type in C++? I am trying to write a function for a class for the prototype: unsigned Rotate(unsigned object, int count) But I don't really get what unsigned means. Shouldn't it be like unsigned int or something? 回答1: From the link above: Several of these types can be modified using the keywords signed, unsigned, short, and long. When one of these type modifiers is used by itself, a data type of int is assumed This means that you can assume

Why is a negative int greater than unsigned int? [duplicate]

泪湿孤枕 提交于 2019-11-26 18:57:40
This question already has an answer here: Comparison operation on unsigned and signed integers 7 answers int main(void) { unsigned int y = 10; int x = – 4; if (x > y) Printf("x is greater"); else Printf("y is greater"); getch(); return (0); } Output: x is greater I thought the output would be y is greater since it is unsigned. What's the reason behind this? Because the int value is promoted to an unsigned int . specifically 0xFFFFFFFC on a 32-bit machine, which as an unsigned int is 4294967292 , considerably larger than 10 C99 6.3.1.1-p2 If an int can represent all values of the original type