signed

Struct variable doesn't changed by assignment

守給你的承諾、 提交于 2019-12-02 13:22:44
struct st { int a1 : 3; int a2 : 2; int a3 : 1; } void main(void) { x.a3 = -1; if (x.a3 == -1) printf("TRUE\n"); else printf("FALSE\n"); x.a3 = 1; if (x.a3 == 1) printf("TRUE\n"); else printf("FALSE\n"); } In case, 'x.a3 = -1;' First if is TRUE . But, why 'x.a3 = 1' doesn't changed in second if ? It's still x.a3 = -1. And If I type 'x.a3 = 1;' in first if, it still x.a3 = = 1 !! It doesn't changed! Debug Result in XCode The problem is, a signed 1 bit variable can hold only two values, -1 and 0 (Read about Two's complement ). It is not sufficient to hold a value of 1 (+ 1 , to be exact). To

C# Unsigned bytes Encryption to Java Signed bytes Decryption

女生的网名这么多〃 提交于 2019-12-02 02:35:01
I have an application in C# that encrypt part of my files (because they are big files) using RijndaelManaged. So I convert my file to byte arrays and encrypt only a part of it. Then I want to decrypt the file using Java. So I have to decrypt only part of the file (means those bytes) that was encrypted in C#. Here the problem comes. Because in C# we have unsigned bytes and in Java we have signed bytes . So my encryption and decryption not working the way I want. In C# I have joined the encrypted bytes and normal bytes together and saved them with File.WriteAllBytes . So I can't use sbyte here

Is there a signed zero Integer in Java?

旧巷老猫 提交于 2019-12-02 01:05:33
I've learned that floating point number s have a signed zero in java. But I'm afraid Integer has not: new Integer("0").equals(new Integer("-0")) // true vs. new Double("0").equals(new Double("-0")) // false How could I store a sign with my zero Integer value? You cannot store a sign with Java integer primitive type. Negative zero is an artifact of IEEE-754 representation, which stores a sign in a separate bit. Integers, on the other hand, are stored in two's complement representation, which has a unique representation for zero. 来源: https://stackoverflow.com/questions/41893756/is-there-a-signed

Swift converting signed array of Int [int8] to unsigned array of Int [UInt8]

谁说我不能喝 提交于 2019-12-02 00:47:15
问题 How to convert signed array of [Int8] to unsigned array of [UInt8]. let arryData: [Int8] = [-108, 11, -107, -14, 35, -57, -116, 118, 54, 91, 12, 67, 21, 29, -44, 111] I just want to convert this above into array of Unsigned [UInt8]. How to achieve this in swift.? Thanks in advance. 回答1: If your intention is to convert signed 8-bit integers to unsigned ones with the same bit representation (e.g. -1 -> 255 ): let intArray: [Int8] = [0, 1, 2, 127, -1, -2, -128] let uintArray = intArray.map {

Swift converting signed array of Int [int8] to unsigned array of Int [UInt8]

百般思念 提交于 2019-12-01 22:08:55
How to convert signed array of [Int8] to unsigned array of [UInt8]. let arryData: [Int8] = [-108, 11, -107, -14, 35, -57, -116, 118, 54, 91, 12, 67, 21, 29, -44, 111] I just want to convert this above into array of Unsigned [UInt8]. How to achieve this in swift.? Thanks in advance. If your intention is to convert signed 8-bit integers to unsigned ones with the same bit representation (e.g. -1 -> 255 ): let intArray: [Int8] = [0, 1, 2, 127, -1, -2, -128] let uintArray = intArray.map { UInt8(bitPattern: $0) } print(uintArray) // [0, 1, 2, 127, 255, 254, 128] [Int8] -> [UInt8] You haven't

C/C++ packing signed char into int

自古美人都是妖i 提交于 2019-12-01 20:51:42
问题 I have need to pack four signed bytes into 32-bit integral type. this is what I came up to: int32_t byte(int8_t c) { return (unsigned char)c; } int pack(char c0, char c1, ...) { return byte(c0) | byte(c1) << 8 | ...; } is this a good solution? Is it portable (not in communication sense)? is there a ready-made solution, perhaps boost? issue I am mostly concerned about is bit order when converting of negative bits from char to int. I do not know what the correct behavior should be. Thanks 回答1:

Why is there one more negative int than positive int?

拈花ヽ惹草 提交于 2019-12-01 18:00:55
问题 The upper limit for any int data type (excluding tinyint ), is always one less than the absolute value of the lower limit. For example, the upper limit for an int is 2,147,483,647 and ABS(lower limit) = 2,147,483,648. Is there a reason why there is always one more negative int than positive int? EDIT: Changed since question isn't directly related to DB's 回答1: The types you provided are signed integers. Let's see one byte(8-bit) example. With 1 byte you have 2^8 combinations which gives you

Why is there one more negative int than positive int?

这一生的挚爱 提交于 2019-12-01 17:12:37
The upper limit for any int data type (excluding tinyint ), is always one less than the absolute value of the lower limit. For example, the upper limit for an int is 2,147,483,647 and ABS(lower limit) = 2,147,483,648. Is there a reason why there is always one more negative int than positive int? EDIT: Changed since question isn't directly related to DB's Lukasz Szozda The types you provided are signed integers. Let's see one byte(8-bit) example. With 1 byte you have 2^8 combinations which gives you 256 possible numbers to store. Now you want to have the same number of positive and negative

Signed left shift behaviour

喜欢而已 提交于 2019-12-01 13:48:31
public class Shift { public static void main(String[] args) { for(int i = 0; i < 32; ++i){ System.out.println(-0x55555555 << i); } } } Running the above code gives the following output -1431655765 1431655766 -1431655764 1431655768 -1431655760 1431655776 -1431655744 1431655808 -1431655680 1431655936 -1431655424 1431656448 -1431654400 1431658496 -1431650304 1431666688 -1431633920 1431699456 -1431568384 1431830528 -1431306240 1432354816 -1430257664 1434451968 -1426063360 1442840576 -1409286144 1476395008 -1342177280 1610612736 -1073741824 -2147483648 While testing with an other value (64) gives a

Signed left shift behaviour

旧城冷巷雨未停 提交于 2019-12-01 12:40:19
问题 public class Shift { public static void main(String[] args) { for(int i = 0; i < 32; ++i){ System.out.println(-0x55555555 << i); } } } Running the above code gives the following output -1431655765 1431655766 -1431655764 1431655768 -1431655760 1431655776 -1431655744 1431655808 -1431655680 1431655936 -1431655424 1431656448 -1431654400 1431658496 -1431650304 1431666688 -1431633920 1431699456 -1431568384 1431830528 -1431306240 1432354816 -1430257664 1434451968 -1426063360 1442840576 -1409286144