473,796 Members | 2,569 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 3381
On 2006-03-06, en******@yahoo. com <en******@yahoo .com> wrote:

Jordan Abel wrote:
On 2006-03-05, en******@yahoo. com <en******@yahoo .com> wrote:
>
> CBFalconer wrote:
>> Actually, under C99, if the underlying hardware has such objects
>> the implementation must then support them. Otherwise they can be
>> omitted.
>
> If you read the relevant paragraph in the standard,
> you'll see that it doesn't say anything about the
> underlying hardware. It's perfectly legal for an
> implementation to have 8 bit chars, 16 bit shorts,
> and 64 bit ints, longs and long longs, and not define
> int32_t, regardless of what hardware it's running on.


I think his claim is that the types have to be available if the relevant
standard types are twos-complement and have no padding. I don't know if
that's true or not. "hardware" is just a shorthand for "whatever the
'native' types are implemented on."


If that's the claim that was intended then someone needs
a lesson in writing for clarity.

I find it more likely that your reading is simply overly
charitable. There was no mention, for example, of twos
complement in the original message.


It's implied in "such objects".
Mar 6 '06 #31

Jordan Abel wrote:
On 2006-03-06, en******@yahoo. com <en******@yahoo .com> wrote:

Jordan Abel wrote:
On 2006-03-05, en******@yahoo. com <en******@yahoo .com> wrote:
>
> CBFalconer wrote:
>> Actually, under C99, if the underlying hardware has such objects
>> the implementation must then support them. Otherwise they can be
>> omitted.
>
> If you read the relevant paragraph in the standard,
> you'll see that it doesn't say anything about the
> underlying hardware. It's perfectly legal for an
> implementation to have 8 bit chars, 16 bit shorts,
> and 64 bit ints, longs and long longs, and not define
> int32_t, regardless of what hardware it's running on.

I think his claim is that the types have to be available if the relevant
standard types are twos-complement and have no padding. I don't know if
that's true or not. "hardware" is just a shorthand for "whatever the
'native' types are implemented on."


If that's the claim that was intended then someone needs
a lesson in writing for clarity.

I find it more likely that your reading is simply overly
charitable. There was no mention, for example, of twos
complement in the original message.


It's implied in "such objects".


Only to someone who already knows what the Standard
says, since twos complement isn't mentioned in any
message in the thread before yours. Obviously, someone
who is writing to explain what the standard says is
assuming that his audience doesn't already know what
it says, otherwise there's no point in explaining it.

Mar 6 '06 #32
On 6 Mar 2006 04:52:50 GMT, in comp.lang.c , Jordan Abel
<ra*******@gmai l.com> wrote:
On 2006-03-06, James Dow Allen <jd*********@ya hoo.com> wrote:

The gets() which I defended gots'ed a string which my own software
had printf'ed. Got it?


How did you guarantee this? There is no mechanism in the standard to
ensure that this happens.


Of course there isn't.

But there's also nothing in the standard that ensures that
fflush(stdout) won't explode a nuclear device. It requires it to clear
the buffer, nothing more. Evaporating the installation would achieve
this handily.

Hyperbole aside, my point is that any part of the standard that
interacts with the outside world is open to abuse. Careful programming
and careful use prevent that, nothing more.

For what its worth I agree, gets() is overly dangerous and it'd be
nice if it were gone. I disagree that its impossible to safely use it.
Its just excessively hard.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Mar 6 '06 #33
On 2006-03-06, Mark McIntyre <ma**********@s pamcop.net> wrote:
On 6 Mar 2006 04:52:50 GMT, in comp.lang.c , Jordan Abel
<ra*******@gmai l.com> wrote:
On 2006-03-06, James Dow Allen <jd*********@ya hoo.com> wrote:

The gets() which I defended gots'ed a string which my own software
had printf'ed. Got it?


How did you guarantee this? There is no mechanism in the standard to
ensure that this happens.


Of course there isn't.

But there's also nothing in the standard that ensures that
fflush(stdout) won't explode a nuclear device. It requires it to clear
the buffer, nothing more. Evaporating the installation would achieve
this handily.

Hyperbole aside, my point is that any part of the standard that
interacts with the outside world is open to abuse. Careful programming
and careful use prevent that, nothing more.

For what its worth I agree, gets() is overly dangerous and it'd be
nice if it were gone. I disagree that its impossible to safely use it.
Its just excessively hard.
Mark McIntyre


Post code that you think safely uses gets and i'll prove it wrong within
the context of the API you are using to "ensure" it. [well, i'm hoping
you're using the unix api, since i wouldn't have the first clue about
any other one]
Mar 6 '06 #34
In article <sl************ ***********@ran dom.yi.org>,
Jordan Abel <ra*******@gmai l.com> wrote:
Post code that you think safely uses gets and i'll prove it wrong within
the context of the API you are using to "ensure" it. [well, i'm hoping
you're using the unix api, since i wouldn't have the first clue about
any other one]


How about something like this:

Open a file w+. Write known data into it. fseek() back to the
beginning of the file. gets() with a buffer at least as big as
the data to be written.

Within standard C, there is nothing that could sneak in and change
the file contents "underneath you". Unix has multiprocessing
and another Unix process could change the file, but that's not the
fault of standard C. And besides, you could run this on a system
that did not offer multiple processes. (Now, if you start going
in and bashing The One True Process with a debugger, clearly C
would not be able to offer any guarantees of anything at all.)
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
Mar 6 '06 #35
ro******@ibd.nr c-cnrc.gc.ca (Walter Roberson) writes:
In article <sl************ ***********@ran dom.yi.org>,
Jordan Abel <ra*******@gmai l.com> wrote:
Post code that you think safely uses gets and i'll prove it wrong within
the context of the API you are using to "ensure" it. [well, i'm hoping
you're using the unix api, since i wouldn't have the first clue about
any other one]


How about something like this:

Open a file w+. Write known data into it. fseek() back to the
beginning of the file. gets() with a buffer at least as big as
the data to be written.


gets() reads from stdin. You'll have to use freopen() to replace
stdin by your file. Seems like a pretty big stretch to make just
to use gets() safely, when you could just use a better designed
function instead.
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Mar 6 '06 #36
On 2006-03-06, Ben Pfaff <bl*@cs.stanfor d.edu> wrote:
ro******@ibd.nr c-cnrc.gc.ca (Walter Roberson) writes:
In article <sl************ ***********@ran dom.yi.org>,
Jordan Abel <ra*******@gmai l.com> wrote:
Post code that you think safely uses gets and i'll prove it wrong within
the context of the API you are using to "ensure" it. [well, i'm hoping
you're using the unix api, since i wouldn't have the first clue about
any other one]


How about something like this:

Open a file w+. Write known data into it. fseek() back to the
beginning of the file. gets() with a buffer at least as big as
the data to be written.


gets() reads from stdin. You'll have to use freopen() to replace
stdin by your file. Seems like a pretty big stretch to make just
to use gets() safely, when you could just use a better designed
function instead.


Is it even permissible to change the mode of stdin?
Mar 6 '06 #37
In article <87************ @benpfaff.org>,
Ben Pfaff <bl*@cs.stanfor d.edu> wrote:
gets() reads from stdin. You'll have to use freopen() to replace
stdin by your file.
True.
Seems like a pretty big stretch to make just
to use gets() safely, when you could just use a better designed
function instead.


Mark's claim is that there exists at least one standards-compliant
system under which at least one standards-complaint program can safely
use gets().

Jordan's claim appears to be that gets() is unsafe for every *possible*
standards-compliant program on every *possible* standards-compliant
environment.

Mark doesn't claim that gets() is safe in every environment or
every program; nor does he claim that the safe program could be
written in (say) less than a million lines of code -- just that
at least one such safe program + environment combination exists.

So... if the safe program involves freopen() on stdin and requires
a single-user mono-tasking environment, then so be it: if it can
be done *at all* then Mark would be right. Mark did say that
it was "excessivel y hard" to do...
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Mar 6 '06 #38
In article <sl************ ***********@ran dom.yi.org>,
Jordan Abel <ra*******@gmai l.com> wrote:
On 2006-03-06, Ben Pfaff <bl*@cs.stanfor d.edu> wrote:
gets() reads from stdin. You'll have to use freopen() to replace
stdin by your file.

Is it even permissible to change the mode of stdin?


C89 does not have an prohibition against it in the description
of freopen(); it might somewhere else, perhaps.

But in this connection, the footnote is informative:

116. The primary use of the freopen function is to change the
file associated with a standard text stream (stderr, stdin,
or stdout), as those identifiers need not be modifiable lvalues
to which the value returned by the fopen function may be assigned.
I would interpret that as being supportive of changing the mode
as well as the association, in that it talks about providing a
mechanism to essentially assign new values to those predefined
identifiers -- and if one *could* just write to those identifiers
(if they were lvalues) then one could put in a stream of a
different mode.

Of course, my interpretation is not to be considered "proof" ;-)

--
There are some ideas so wrong that only a very intelligent person
could believe in them. -- George Orwell
Mar 6 '06 #39
On 2006-03-06, Walter Roberson <ro******@ibd.n rc-cnrc.gc.ca> wrote:
In article <sl************ ***********@ran dom.yi.org>,
Jordan Abel <ra*******@gmai l.com> wrote:
On 2006-03-06, Ben Pfaff <bl*@cs.stanfor d.edu> wrote:

gets() reads from stdin. You'll have to use freopen() to replace
stdin by your file.

Is it even permissible to change the mode of stdin?


C89 does not have an prohibition against it in the description
of freopen(); it might somewhere else, perhaps.

But in this connection, the footnote is informative:

116. The primary use of the freopen function is to change the
file associated with a standard text stream (stderr, stdin,
or stdout), as those identifiers need not be modifiable lvalues
to which the value returned by the fopen function may be assigned.
I would interpret that as being supportive of changing the mode
as well as the association, in that it talks about providing a
mechanism to essentially assign new values to those predefined
identifiers -- and if one *could* just write to those identifiers
(if they were lvalues) then one could put in a stream of a
different mode.

Of course, my interpretation is not to be considered "proof" ;-)


My interpretation is the opposite - that it's intended to change stdin
to be _another file_ open in read mode, or stdout/stderr to another file
open in write mode.

It's also possible that on some systems extra magic may be needed to
make a re-opened stdout become the standard output of a command executed
via system(), or even for a re-opened stream to become the standard
stream used by functions not implemented in standard C such as perror().
It also might be desirable for the buffering state of a stream to be
retained in some cases. For example, there is a good reason why stderr
is not fully buffered at program start. (It's unclear to me whether
freopen can even change the buffering state at all - though it could be
desirable to do so when changing stdout to be a regular file when it was
an interactive device at program startup)
Mar 6 '06 #40

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

Similar topics

8
3272
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
1564
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
2367
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
1643
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
3713
by: kerravon | last post by:
The following C program: int main(void) { int x = -2147483648; return (0); } Produces the following warning:
0
22480
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
5971
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
9528
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
10455
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
10228
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
10173
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
9052
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?
1
4116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2925
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.