473,785 Members | 2,789 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dealing with a large integer

Hi all

I have an large integer in this format
x1*256^5 + x2*256^4 + x3*256^3 + x4*256^2 + x5*256 + x6
now I must convert it to this format
y1*900^4 + y2*900^3 + y3*900^2 + y4*900 + y5

x1-x5 is given.I must get y1-y4 from it.

How can I do this on my 32bit PC?

Sorry for that my English is poor.

Thanks.

Mar 3 '06
42 3377
Default User wrote:
yong wrote:
I'm using linux.And I found another variable type named uint64_t in
stdint.h which represents a 64bit integer.It's seems not standard but
very useful.


Actually, that is standard as of the latest standard. From the C99
draft standard:


Right, but gcc does not implement C99. So its existence is actually an
extension to gcc (perhaps yong has some other compiler on Linux that
actually does support C99.) Of course you can get this "extension" for
many more compilers than just gcc from here:

http://www.pobox.com/~qed/pstdint.h

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

Mar 4 '06 #11
ge**********@gm ail.com wrote:
yong wrote:
I have an large integer in this format
x1*256^5 + x2*256^4 + x3*256^3 + x4*256^2 + x5*256 + x6
now I must convert it to this format
y1*900^4 + y2*900^3 + y3*900^2 + y4*900 + y5

x1-x5 is given.I must get y1-y4 from it.

How can I do this on my 32bit PC?

Sorry for that my English is poor.
You can try to be fancy about modulo arithmetic and get it done with
32-bit integers,


I would actually endorse and recommend this method. Its the most
portable way to do it, and its just a little math.
[...] but since you are posting to comp.lang.c, your machine
ought to implement "double." In IEEE floating point, doubles have a 52
bit mantissa, which is big enough to hold both 256^6 and 900^5.
Uhhh ... does ANSI C insist that double have sufficient range for
numbers of this size? Turbo C implements double's as 32-bit floats
(but Turbo C is not a fully compliant ANSI C compiler so that might not
prove anything.)
[...] So just compute

double f = x[1];
for (i = 2; i <= 6; i++)
f = f * 256 + x[i];
for (i = 5; y >= 1; y--) {
y[i] = f % 900;


This is illegal, you should use the modf() function instead: y[i] =
900 * modf (f / 900, &f);

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

Mar 4 '06 #12
"Default User" <de***********@ yahoo.com> writes:
yong wrote:

I'm using linux.And I found another variable type named uint64_t in
stdint.h which represents a 64bit integer.It's seems not standard but
very useful.


Actually, that is standard as of the latest standard. From the C99
draft standard:
7.18.1.1 Exact-width integer types

[#2] The typedef name uintN_t designates an unsigned integer
type with width N. Thus, uint24_t denotes an unsigned
integer type with a width of exactly 24 bits.
An implementation is not required to provide them.


It /is/ required to provide them for widths of 8, 16, 32 or 64 bits, if:

- it is a C99 implementation, and
- it is actually capable of providing them.

-Micah
Mar 4 '06 #13
"James Dow Allen" <jd*********@ya hoo.com> writes:
[...]
<OT>
Note 2. Bill Gates was afriad to empower you by offering 'bc'?
Download Linux.


I have "bc" on my Windows systems, under Cygwin.
</OT>

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 4 '06 #14
we******@gmail. com writes:
ge**********@gm ail.com wrote:
[...] but since you are posting to comp.lang.c, your machine
ought to implement "double." In IEEE floating point, doubles have a 52
bit mantissa, which is big enough to hold both 256^6 and 900^5.


Uhhh ... does ANSI C insist that double have sufficient range for
numbers of this size? Turbo C implements double's as 32-bit floats
(but Turbo C is not a fully compliant ANSI C compiler so that might not
prove anything.)


It only insists that IEEE floating point is used if __STDC_IEC_559_ _
is defined. I don't have the standard, but wikipedia seems to bear
these figures out in this case.

If IEEE floating point is not available (improbable), it's still
guaranteed that a double can hold 10 decimal digits, which means that
it is big enough to hold (10^10)-1. This only means it's enough to
hold 4 complete base-256 digits, or 3 base-900 digits, which is not
enough for the specified needs.
Mar 4 '06 #15
On 2006-03-04, Micah Cowan <mi***@cowan.na me> wrote:
"Default User" <de***********@ yahoo.com> writes:
yong wrote:

> I'm using linux.And I found another variable type named uint64_t in
> stdint.h which represents a 64bit integer.It's seems not standard but
> very useful.


Actually, that is standard as of the latest standard. From the C99
draft standard:
7.18.1.1 Exact-width integer types

[#2] The typedef name uintN_t designates an unsigned integer
type with width N. Thus, uint24_t denotes an unsigned
integer type with a width of exactly 24 bits.
An implementation is not required to provide them.


It /is/ required to provide them for widths of 8, 16, 32 or 64 bits, if:

- it is a C99 implementation, and
- it is actually capable of providing them.

-Micah


I was trying to think of a way that an implementation could prove that
an implementation is capable of providing them if it doesn't, but i just
thought of one:

#include <limits.h>
#include <inttypes.h>

int main() {
#ifndef INT16_MAX
#if CHAR_BIT == 16 && SCHAR_MAX == 32767 && SCHAR_MIN == -32768
signed char x;
*(unsigned char *)&x = 0x80;
if(x == SCHAR_MIN) puts("bad");
#elif CHAR_BIT == 8 && SHRT_MAX == 32767 && SHRT_MIN == -32768
if(sizeof(short ) == 2) {
*(unsigned short *)&x = 0x8000;
if(x == SHRT_MIN) puts("bad");
}
#endif
#endif/*no int16_t*/
}

On any conforming implementation, i believe the above program will have
no output.
Mar 4 '06 #16
we******@gmail. com writes:
Default User wrote:
yong wrote:
> I'm using linux.And I found another variable type named uint64_t in
> stdint.h which represents a 64bit integer.It's seems not standard but
> very useful.
Actually, that is standard as of the latest standard. From the C99
draft standard:


Right, but gcc does not implement C99. So its existence is actually an
extension to gcc (perhaps yong has some other compiler on Linux that
actually does support C99.)


gcc doesn't *fully* support C99 (see <http://gcc.gnu.org/c99status.html>
for details), but it does support some C99 features. But <stdint.h>,
the header that defines uint64_t, is part of the library, not the
compiler. gcc uses whatever library is provided by the system. On
Linux, that's glibc, which does support <stdint.h>; on other systems,
it's likely going to depend on the operating system.
Of course you can get this "extension" for
many more compilers than just gcc from here:

http://www.pobox.com/~qed/pstdint.h


Or here:

http://www.lysator.liu.se/c/q8/

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 4 '06 #17
we******@gmail. com writes:
ge**********@gm ail.com wrote:
yong wrote:
> I have an large integer in this format
> x1*256^5 + x2*256^4 + x3*256^3 + x4*256^2 + x5*256 + x6
> now I must convert it to this format
> y1*900^4 + y2*900^3 + y3*900^2 + y4*900 + y5
>
> x1-x5 is given.I must get y1-y4 from it.
>
> How can I do this on my 32bit PC?
>
> Sorry for that my English is poor.


You can try to be fancy about modulo arithmetic and get it done with
32-bit integers,


I would actually endorse and recommend this method. Its the most
portable way to do it, and its just a little math.
[...] but since you are posting to comp.lang.c, your machine
ought to implement "double." In IEEE floating point, doubles have a 52
bit mantissa, which is big enough to hold both 256^6 and 900^5.


Uhhh ... does ANSI C insist that double have sufficient range for
numbers of this size? Turbo C implements double's as 32-bit floats
(but Turbo C is not a fully compliant ANSI C compiler so that might not
prove anything.)


The standard requires
FLT_DIG >= 6
DBL_DIG >= 10
LDBL_DIG >= 10
I don't think a 32-bit float would satisfy the requirement for DBL_DIG.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 4 '06 #18
Default User wrote:
yong wrote:
I'm using linux.And I found another variable type named uint64_t
in stdint.h which represents a 64bit integer.It's seems not
standard but very useful.


Actually, that is standard as of the latest standard. From the C99
draft standard:

7.18.1.1 Exact-width integer types

[#2] The typedef name uintN_t designates an unsigned integer
type with width N. Thus, uint24_t denotes an unsigned
integer type with a width of exactly 24 bits.

An implementation is not required to provide them.


Actually, under C99, if the underlying hardware has such objects
the implementation must then support them. Otherwise they can be
omitted. #ifdef may be handy.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>
Mar 5 '06 #19
Keith Thompson wrote:
"James Dow Allen" <jd*********@ya hoo.com> writes:
[...]
<OT>
Note 2. Bill Gates was afriad to empower you by offering 'bc'?
Download Linux.
I have "bc" on my Windows systems, under Cygwin.


under DJGPP here.
+ </OT>


--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>
Mar 5 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3271
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run simultaneously 4 similar queries it takes nearly 5 minutes instead of 4 times 9 seconds or something near of that. here is a sample query: select mertido, fomeazon, ertektipus, mertertek from t_me30 where fomeazon in (select distinct fomeazon...
18
5643
by: Zero | last post by:
Hi, I am calculating an integer to the pwer of a large integer, e.g. 2^5000. It turns out that the result I always get is zero. I am sure that the result is too large to store in such type as u_int64_t and long int etc. My power function is as follows: for(i=0; i<5000; i++) result *= 2;
5
1563
by: platinumbay | last post by:
I am trying to load large flat files; > 250 MB. What is the best practice for this? I have already read through everything I could find on Google, to no avail. I have a SQL DTS process that will load the file in about 7 minutes. My code takes about an hour. Here is a snippet: Dim objSR As StreamReader = System.IO.File.OpenText(objOrigFile)
3
2366
by: sebastian.harko | last post by:
Helllo, What's the general accepted strategy for dealing with very large binary files in C# ? I have to do a program that reads some "multi frame bitmap " files which can reach up to one hundred megs so I need to know how to optimize reading a file.. Best regards, Seb
1
1642
by: Jonathan Wilson | last post by:
I am working on some software which has to deal with data that could be as large as 500mb or so. Currently I am using new and delete to manage this memory but I find it is not ideal and sometimes gives out of memory errors if I open one large data item then free that data item then another large data item even though I have enough memory (including 2GB of physical RAM and 100GB of free disk space for swap file). Are there any functions...
26
3710
by: kerravon | last post by:
The following C program: int main(void) { int x = -2147483648; return (0); } Produces the following warning:
0
22476
by: zephyrus360 | last post by:
This is about a technique to find the mod of a very large integer with a normal small integer. I recently encountered this problem when I needed to compute the modulus of a very large number with a normal integer. I needed this in a C++ program running on a 32-bit UNIX platform. The problem was that the number was 28 digits long and no native datatype in c++ could store a number of that size. (Eg: 1088263455689473669888943602 % 380) Not...
4
5970
by: Shisou | last post by:
hello everyone, Well I tried to solve this one on my own but it seems i need your help again :\ I'm trying to write a program to add or subtract two large integers... easy enough.. Where i run into problems is working with pointers. Here's where i'm at right now. I have a function that takes in the integers as strings and puts it into a struct
16
2045
by: pereges | last post by:
ok so i have written a program in C where I am dealing with huge data(millions and lots of iterations involved) and for some reason the screen tends to freeze and I get no output every time I execute it. However, I have tried to reduce the amount of data and the program runs fine. What could possibly be done to resolve this ?
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
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...
0
9953
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
8978
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
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
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...
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
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.