Will have
int a, b, c;
Let int be represented by 4 bytes. Say a + b requires 1 bit more than 4 bytes (i.e., suppose the result is 1 00 .... 0 (32 zeros, in binary)). This will result in C = 0, and I'm sure the computer microprocessor will set some kind of overflow flag. Is there a built-in method for checking this in C?
I am really working on creating a type of number with a length of 1024 bits (for example, int is a built-in type of number with a length of 32 bits). I tried using an unsigned char array with 128 elements. I also need to define the operations of adding and subtracting these numbers. I wrote the code to add, but I have a problem with subtraction. I donβt have to worry about getting negative results, because the way I will call the subtraction function always ensures that the subtraction result is always positive, but to implement the subtraction function I need to somehow get 2 additions to the subtraction, that is my own 1024 -bit number.
I apologize if it is difficult to understand my description. If necessary, I will clarify this. I include code for the add function and an incomplete subtraction function. NUM_OF_WORDS is a constant declared as
#define NUM_OF_WORDS 128
Please let me know if you do not understand my question or any part of my code.
PS: I donβt see how to upload attachments in this forum, so I am directing you to another site. My code can be found there
click on download on this page
By the way, I found this. I intend to replace INT_MAX by UCHAR_MAX , since my 1024-bit numbers consist of an array of char types (8-bit variable). Is this check sufficient for all cases?
Update:
Yes, I am working on cryptography.
I need to implement the Montgomery Multiplication routine for 1024-bit integers.
I also looked at using the GMP library, but I was not able to find out how to use it. I looked through the tutorial, and after several small modifications, I managed to compile the GMP project file in VC ++ 6, which resulted in a lot of .obj files, but now I'm not sure what to do with them. Nevertheless, it would be nice if I could write my own data types, as this will give me full control over how arithmetic operations work with my user data type, and I also need to be able to expand it from 1024 bits to large numbers to the future.