473,796 Members | 2,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiplication Without Carry in C (using GMP Lib)

3 New Member
I was using GMP library for build an binary arithmetic, but for multiplication, I want to return a result a multiplication without carry..
How can I implementing it?
nb: the code below give a result of multiplication with carry

Expand|Select|Wrap|Line Numbers
  1. void multi(){
  2.      int m_bit;int m_bit2;
  3.      char *op1;
  4.      char *op2;     
  5.      char *final;
  6.  
  7.      mpz_t hasil_acak,hasil_acak2,hasil_pangkat,hasil_exor_temp,hasil_multi,hasil_multi_temp,hasil_exor_temp0;
  8.  
  9.      mpz_init(hasil_pangkat);
  10.      mpz_init(hasil_acak);
  11.      mpz_init(hasil_acak2);
  12.      mpz_init(hasil_exor_temp0);
  13.      mpz_init(hasil_exor_temp);
  14.      mpz_init(hasil_multi_temp);
  15.  
  16.      mpz_init(hasil_multi);
  17.  
  18.      printf("input m-bit pertama: "); scanf("%d",&m_bit);
  19.      gmp_randstate_t rand_state;
  20.      gmp_randinit_default(rand_state);
  21.      gmp_randseed_ui (rand_state, time(NULL));
  22.      mpz_rrandomb(hasil_acak, rand_state, m_bit);
  23.      //mpz_get_ui(hasil_acak);     
  24.      op1 = mpz_get_str(NULL, 2, hasil_acak);
  25.      printf("[%s]\n", op1);
  26.  
  27.      printf("input m-bit kedua: "); scanf("%d",&m_bit2);
  28.      gmp_randstate_t rand_state2;
  29.      gmp_randinit_default(rand_state2);
  30.      gmp_randseed_ui (rand_state2, time(NULL));
  31.      mpz_rrandomb(hasil_acak2, rand_state2, m_bit2);
  32.      op2 = mpz_get_str(NULL, 2, hasil_acak2);
  33.      printf("[%s]\n", op2);
  34.  
  35.      mpz_addmul(hasil_multi, hasil_acak, hasil_acak2);//can I use other function or any code for replace this multiplication with carry? (I want a result of mutiplication without carry)
  36.      mpz_get_ui(hasil_multi);
  37.      final = mpz_get_str(NULL, 2, hasil_multi);
  38.      puts ("\n\nHasil MULTI:");
  39.      printf("[%s]\n", op1);printf("[%s]\n", op2);
  40.      puts("_*_");
  41.      printf("[%s]\n", final);
  42.  
  43. }
  44.  
Jul 14 '10 #1
0 1723

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1934
by: slashman | last post by:
Hi, I wud like to know how to create and use .lib files from a few c++ classes i have created that are common to a lot of my projects. My guess is .lib files can b used in windows and linux (please correct me if i'm worng). And if u guys cud also let me know where i cud find out such information in the future (books or websites) it would b x-tremely helpful thanks in advance vivek
0
1078
by: Marco Segurini | last post by:
Hi, Actually the build of my solution gives as result an EXE and some DLLs. Now, I am creating a new configuration that tranform the DLLs into LIBs. The following semplified code explains one of the problems that arise using a solution with a console project that creates the EXE and a lib project that creates the LIB. //------------------------------------------------------------------------
0
975
by: Leszek Gruszka | last post by:
I have dhcpsapi.lib and dhcpsapi.h files. I know, that *.h is for c++/c#. Is there any method to use it in vb .net?
4
7472
by: Sameh Ahmed | last post by:
Hello there Is there a way to use lib files as com objects? I have an SDK of an API used to communicate with an EMC storage box that contains only LIB, DLL, and C files. Is there way to use these files in Vb.net? Thanks in advance. Regards
6
4615
by: radishcarrot | last post by:
Hi, I try to access the QuickTime COM/ActiveX DLL file, QTOControl.dll in my VC++ codes as follows: HINSTANCE OTOControlLib = LoadLibrary("QTOControl.dll"); But how do I access the methods in the dll file?? The problem lies in that QuickTime did not provide the .h or .lib file for the DLL file?? Any solution?? Thanks alot
17
5180
by: Hugh | last post by:
I would like to perform an addition without carrying of two integers... I've got no idea how to do this in python, although I've been using it for web/cgi/db work for a few years now. Any help would be great. Hugh
0
4118
by: outofstep | last post by:
Hit me up on AIM/YIM (oipaloi). I'm not a code monkey and would like to get some advice. Or hit up this thread right here. I'm using DEV C++ as my compiler. I'm trying to calculate SIN/COS/TAN, etc without the use of CMATH. Using two recursive functions for the power and factorial. Gotta do some other things as well, but right now I'm just wondering why my values are off. Just wondering where I'm going wrong. Here's the code I've got...
3
4501
by: sunmat | last post by:
To find number of character without space using java Example: String = prabu sun No. of char =8 plz send me code
4
1600
by: siluomm | last post by:
hi.....i am btech2nd year student.please send me the programming of multiplication of two array using operator overloading concept in c++
7
2025
by: JDOMPer | last post by:
Don’t misunderstand me – I use AJAX, but I think there is a far simpler, elegant alternative that just uses Javascript, the DOM and Php ( hence - JDOMP) for data transfers, and is cross-browser without the need for work arounds. JDOMP works in recent versions of Explorer, Mozilla, Safari and Opera. Please note I will not deal with security issues which are always an issue whenever there is access to a database. You can simply change text on...
0
9679
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10172
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.