unsigned-integer

How to get an unsigned byte array from a BigInteger in Java?

社会主义新天地 提交于 2021-02-07 21:10:20
问题 I need to convert a BigInteger to an unsigned integer encoded in big-endian format but I am having issues since BigInteger.toByteArray returns a signed representation. How can I convert this value to an unsigned format? (Relatively) Helpful Background I am working on some code that uses JNI to have c++ call some Java methods to handle some cryptographic functionality (this is a Microsoft CNG provider that offloads some functionality to Java). I have the public key in Java and the BigInteger

Unsigned Multiplication using Signed Multiplier

偶尔善良 提交于 2021-01-29 07:18:08
问题 I have been assigned with a task to perform unsigned multiplication using signed multiplier. Despite multiple attempts, I couldn't get it. Is it possible to do this? Code: #include <stdio.h> int main() { // Must be short int short int a=0x7fff; short int b=0xc000; unsigned int res1; signed int res2; //unsigned multiplier res1= (unsigned short int) a * (unsigned short int) b; //signed multiplier res2= (short int) a * (short int) b; printf("res1: 0x%x %d \n res2: 0x%x %d\n",res1,res1,res2,res2)

Unsigned integers in assembly

时光怂恿深爱的人放手 提交于 2020-11-28 08:35:29
问题 Brand new to assembly need some help with unsigned arithmetic. Converting from a C program is that means anything. Using: Linux NASM x86 (32 Bit) I want to read in a number from the user. I want this number to be unsigned. When I enter a number above the signed integer limit and use info registers, I notice that my register storing that is negative which means an overflow happened. (Obviously number entered is below max unsigned int) How do I treat this register as unsigned so I can do

Unsigned integers in assembly

陌路散爱 提交于 2020-11-28 08:34:27
问题 Brand new to assembly need some help with unsigned arithmetic. Converting from a C program is that means anything. Using: Linux NASM x86 (32 Bit) I want to read in a number from the user. I want this number to be unsigned. When I enter a number above the signed integer limit and use info registers, I notice that my register storing that is negative which means an overflow happened. (Obviously number entered is below max unsigned int) How do I treat this register as unsigned so I can do

can an enum hold unsigned integers greater than INT_MAX?

▼魔方 西西 提交于 2020-07-09 09:48:11
问题 enum Some_Flag { SOME_FLAG_A = 0x00000000u, SOME_FLAG_B = 0x00000001u, SOME_FLAG_C = 0x00000002u, /* ... */ SOME_FLAG_Z = 0x80000000u, }; uint32_t a; a = SOME_FLAG_Z; Assuming 32 bit integers... Is this valid in C? The standard seems ambiguous to me. EDIT: Quoting the standard: 6.4.4.3 Enumeration constants Semantics 2 An identifier declared as an enumeration constant has type int. Forward references: enumeration specifiers (6.7.2.2). 6.7.2.2 Enumeration specifiers Constraints 2 The

Comparison size_t variable with -1 (maximum size value) in c++ code

无人久伴 提交于 2020-06-01 04:14:50
问题 I'm refactoring a library and trying to get rid of many gcc warnings. The big part of these warning are about signed / unsigned comparison and are related to the usage of size_t . The library works on 64 bit Linux systems. A programmer used -1 as the special value similar to std::string::npos . There are many places in the library where code looks like this: class AnnotationBase { public: size_t m_offset = -1; size_t m_length = -1; } ... AnnotationBase foo(const std::string& text, const

Comparison size_t variable with -1 (maximum size value) in c++ code

倾然丶 夕夏残阳落幕 提交于 2020-06-01 04:14:24
问题 I'm refactoring a library and trying to get rid of many gcc warnings. The big part of these warning are about signed / unsigned comparison and are related to the usage of size_t . The library works on 64 bit Linux systems. A programmer used -1 as the special value similar to std::string::npos . There are many places in the library where code looks like this: class AnnotationBase { public: size_t m_offset = -1; size_t m_length = -1; } ... AnnotationBase foo(const std::string& text, const

Unreasonable behavior on mixing signed and unsigned integers

情到浓时终转凉″ 提交于 2020-01-30 02:30:10
问题 Motivated from a code snippet on this blog under "What happens when I mix signed and unsigned integers?" I decided to run it with few different values of signed and unsigned integers and observe the behaviour. Here is the original snippet (slightly modified, however intent is still same) #include <stdio.h> int main(void) { unsigned int a = 6; int b = -20; int c = (a+b > 6); unsigned int d = a+b; printf("<%d,%u>", c, d); } OUTPUT: <1,4294967282> Now when I run the same program for a = 6 and b