representation

UnicodeDecodeError: 'ascii' codec can't decode

拜拜、爱过 提交于 2019-12-14 00:31:59
问题 I'm reading a file that contains Romanian words in Python with file.readline(). I've got problem with many characters because of encoding. Example : >>> a = "aberație" #type 'str' >>> a -> 'abera\xc8\x9bie' >>> print sys.stdin.encoding UTF-8 I've tried encode() with utf-8, cp500 etc, but it doesn't work. I can't find which is the right Character encoding I have to use ? thanks in advance. Edit: The aim is to store the word from file in a dictionnary, and when printing it, to obtain aberație

What type should I use for binary representation of C enum?

岁酱吖の 提交于 2019-12-13 16:31:11
问题 As I know C enum is unsigned integer, but this may vary by implementation. What type should I use for the enum in binary representation? *PS 'binary representation' means byte-array. I want to serialize enum values to socket to inter-operate with other programs. 回答1: It's up to the compiler to use an int to represent an enum type, or a long if an int is not sufficient to hold all the values of the enum . If you know that all your enum values can be represented by an int , then you can safely

Number of numbers between 2 and 3 in IEEE-754

﹥>﹥吖頭↗ 提交于 2019-12-13 03:55:16
问题 i am learning IEEE-754 representation of numbers. I know how to convert from binary to IEEE and on vice versa. Now i am trying to figure out how to find out how many numbers in single precision are for instance between 2 and 3. So, the sign will be the same for both. Fraction will be a combination i think and exponent is dependent from a proper number(because of shifts). WHat would be a clever way to do it right ? I would be grateful for any help. 回答1: Using a handy online IEEE-754 conversion

Representation and efficiency of Switch statements in bytecode?

只谈情不闲聊 提交于 2019-12-12 13:06:04
问题 Though a switch statement can be represented as a series of if statements, it appears that when a Java switch statement is compiled into bytecode, a different approach is used. What is the representation used by bytecode? I assume this alternate representation is for efficiency reasons, so how does the efficiency compare to that of just an if statement representation? Are there any other considerations that have led to using this representation? 回答1: Read the spec . In Java, if you code a

How to use Int64 in C#

旧时模样 提交于 2019-12-12 09:36:21
问题 The question is easy! How do you represent a 64 bit int in C#? 回答1: 64 bit int is long 回答2: System.Int64 is the .net type, in C# it's also called long 回答3: A signed 64 bit integer is long , an unsigned is ulong . The corresponding types in the framwwork are System.Int64 and System.UInt64 , respectively. Example: long bigNumber = 9223372036854775807; 回答4: By using the long data type, or ulong for unsigned. Table of Integral C# Types 来源: https://stackoverflow.com/questions/3845205/how-to-use

subclassing int to attain a Hex representation

有些话、适合烂在心里 提交于 2019-12-11 01:07:57
问题 Basically I want to have access to all standard python int operators, eg __and__ and __xor__ etc, specifically whenever the result is finally printed I want it represented in Hex format. (Kind of like putting my calculator into Hex mode) class Hex(int): def __repr__(self): return "0x%x"%self __str__=__repr__ # this certainly helps with printing if __name__=="__main__": print Hex(0x1abe11ed) ^ Hex(440720179) print Hex(Hex(0x1abe11ed) ^ Hex(440720179)) Ideally BOTH line of output should be

Cast some light on population count algorithm

橙三吉。 提交于 2019-12-10 19:19:35
问题 I looked for good methods to do popcount (count of set bits). I found this one, here http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan unsigned int v; // count the number of bits set in v unsigned int c; // c accumulates the total bits set in v for(c = 0; v; c++) { v &= v - 1; // clear the least significant bit set } Trying on a few examples, its true that it works. What property of binary operations / representation makes it work? Could you hint at some further

Compilers and negative numbers representations

雨燕双飞 提交于 2019-12-10 14:23:14
问题 Recently I was confused by this question. Maybe because I didn't read language specifications (it's my fault, I know). C99 standard doesn't say which negative numbers representation should be used by compiler. I always thought that the only right way to store negative numbers is two's complement (in most cases). So here's my question: do you know any present-day compiler that implements by default one's complement or sign-magnitude representation? Can we change default representation with

Are repr and str always identical on Pythons builtin numeric types?

六眼飞鱼酱① 提交于 2019-12-10 14:09:53
问题 Are repr and str identical on Pythons built-in numeric types ( int , bool , float , and complex ), or are there (esoteric?) situations where the two may yield different results? Related questions on SO (such as this one) focus on how __repr__ and __str__ may be implemented differently, and return different values for strings, but I can't find anything on the actual implementation on numbers. 回答1: Your primary source of information on this is http://hg.python.org/cpython/file/tip/Objects For

perl6 - Converting data in a Blob into a Num

不问归期 提交于 2019-12-10 13:18:09
问题 I've got some bytes in a blob, an immutable buffer for binary data and I am looking for a way to convert what it holds into a floating point data structure, Num, since it is the class that fits all those 3 formats that could be in the $blob IEEE Float IEEE Double IEEE Long Double What would be the best way of doing that conversion? 回答1: Import NativeCall , perform a cast to a pointer of desired type and dereference the result: use NativeCall; nativecast(Pointer[num32], $blob).deref; 来源: https