General [M]ayhem

Go Back   General [M]ayhem > Real Time Sub-Forums > CompuGlobalHyperMegaNet
Register Members List Mark Forums Read [M]erchandise Calendar

Reply
 
Thread Tools
Redrum
Crate&Barrel Roll
 
Redrum's Avatar
 
what jehanum said

cin the character string char by char, run atoi char by char, then output the integer into an array of ints, int by int

this will let convert huge strings of chars to massive numbers
__________________
lol
Old 04-26-2012, 02:45 PM Redrum is offline  
Reply With Quote
#16  

Advertisement [Remove Advertisement]

DreamWarrior
 
Quote:
Originally Posted by Redrum View Post
what jehanum said

cin the character string char by char, run atoi char by char, then output the integer into an array of ints, int by int

this will let convert huge strings of chars to massive numbers
Why the fuck would you do that? Sure, an array of useless numbers that you'll have to design your own addition and multiplication logic on.... For that matter, one that is a large fucking waste of space! You need 4 bits to represent 10 decimal digits, you're going to stuff them in 32 bit ints in an array? GENIUS! Even using a char array is a fucking waste of 4 bits per.... No real bigint library would be implemented like that.

If uint64_t is available, use that. If that is not enough bits, pull down a bigint library, there are a few that were submitted for inclusion in Boost but didn't make it.

Edit: and Graze, dude, not to be a dick, but if you are too ignorant to figure out that you are overflowing an integer, you certainly are not smart enough to properly reinvent this wheel.

Last edited by DreamWarrior; 04-26-2012 at 07:31 PM..
Old 04-26-2012, 07:21 PM DreamWarrior is offline  
Reply With Quote
#17  

Grazehell
 
Grazehell's Avatar
 
Quote:
Originally Posted by DreamWarrior View Post
Why the fuck would you do that? Sure, an array of useless numbers that you'll have to design your own addition and multiplication logic on.... For that matter, one that is a large fucking waste of space! You need 4 bits to represent 10 decimal digits, you're going to stuff them in 32 bit ints in an array? GENIUS! Even using a char array is a fucking waste of 4 bits per.... No real bigint library would be implemented like that.

If uint64_t is available, use that. If that is not enough bits, pull down a bigint library, there are a few that were submitted for inclusion in Boost but didn't make it.

Edit: and Graze, dude, not to be a dick, but if you are too ignorant to figure out that you are overflowing an integer, you certainly are not smart enough to properly reinvent this wheel.


This entire exercise is me learning C++. Don't get on your high horse about it. There were other ways I could have gone about this that would have actually worked but would not have taken me down the path of strol or stroll. Something my 1000 page C++ book never mentions and only mentions atoi eight time.
My idea isn't necessarily to successfully reinvent the wheel but what I learn trying.

Last edited by Grazehell; 04-26-2012 at 08:48 PM..
Old 04-26-2012, 08:38 PM Grazehell is offline  
Reply With Quote
#18  

Jehannum
 
Jehannum's Avatar
 
Quote:
Originally Posted by DreamWarrior View Post
Why the fuck would you do that? Sure, an array of useless numbers that you'll have to design your own addition and multiplication logic on.... For that matter, one that is a large fucking waste of space! You need 4 bits to represent 10 decimal digits, you're going to stuff them in 32 bit ints in an array? GENIUS! Even using a char array is a fucking waste of 4 bits per.... No real bigint library would be implemented like that.

If uint64_t is available, use that. If that is not enough bits, pull down a bigint library, there are a few that were submitted for inclusion in Boost but didn't make it.

Edit: and Graze, dude, not to be a dick, but if you are too ignorant to figure out that you are overflowing an integer, you certainly are not smart enough to properly reinvent this wheel.
Yeah, but a uint64_t is only going to support a number 19 digits long, and apparently this guy's got really long strings of binary. a char array is really the way to go here, assuming a large integer class isn't in the offering.
__________________
Your powers are useless! I'm wearing my tin foil underwear!

1992 300ZX: Not stock, 433 RWHP
1971 240Z: Toyota front brakes, 123 RWHP
1967 Pontiac GTO: not stock.
Old 04-26-2012, 08:39 PM Jehannum is offline  
Reply With Quote
#19  

DreamWarrior
 
Quote:
Originally Posted by Jehannum View Post
Yeah, but a uint64_t is only going to support a number 19 digits long, and apparently this guy's got really long strings of binary. a char array is really the way to go here, assuming a large integer class isn't in the offering.
A char array is not the way to go if you have to do math. If you don't have to do math, then some would argue to always use string (though I don't advocate that sort of useless waste, lol.)
Old 04-26-2012, 08:45 PM DreamWarrior is offline  
Reply With Quote
#20  

Great Tiger
 
my brain hurts in here.
__________________
"Any human with delicate enough olfactory senses will be able to establish that Tibbles is indeed my cat, since I pissed on her last time I saw her do it." - FLARE
I mean my penis is a solid 4" long and it fits fine in the finger. - 0dan0
Old 04-26-2012, 09:21 PM Great Tiger is offline  
Reply With Quote
#21  

:ninja:
My cooter sweats, and reeks like rotting sea vermon.
 
:ninja:'s Avatar
 
1000 page C++ books and character arrays to do string binary to integer conversion?

Last time I leave my embedded C cave. You guys are nuts.
__________________
Use Linux and BSD
Old 04-26-2012, 10:01 PM :ninja: is offline  
Reply With Quote
#22  

Jehannum
 
Jehannum's Avatar
 
Quote:
Originally Posted by DreamWarrior View Post
A char array is not the way to go if you have to do math. If you don't have to do math, then some would argue to always use string (though I don't advocate that sort of useless waste, lol.)

I'm pretty sure whatever he's doing is in that category anyhow (useless waste).
__________________
Your powers are useless! I'm wearing my tin foil underwear!

1992 300ZX: Not stock, 433 RWHP
1971 240Z: Toyota front brakes, 123 RWHP
1967 Pontiac GTO: not stock.
Old 04-27-2012, 05:29 AM Jehannum is offline  
Reply With Quote
#23  

aoeoae
 
aoeoae's Avatar
 
Quote:
Originally Posted by :ninja: View Post
1000 page C++ books and character arrays to do string binary to integer conversion?

Last time I leave my embedded C cave. You guys are nuts.
i wonder if he's using deitel. i felt like i was wasting my time with C++ until i switched to much more concise book (accelerated C++, koenig & moo). then i switched to a more concise language, python
Old 04-29-2012, 09:32 AM aoeoae is offline  
Reply With Quote
#24  

Grazehell
 
Grazehell's Avatar
 
Quote:
Originally Posted by aoeoae View Post
i wonder if he's using deitel. i felt like i was wasting my time with C++ until i switched to much more concise book (accelerated C++, koenig & moo). then i switched to a more concise language, python

The book is fine. But you really can't expect me to learn everything from reading a book?

Seems like people a bit confused as to what the program was suppose to do. It was suppose to take in a wall of binary numbers and process them, not just them convert to decimal
Old 04-29-2012, 09:50 AM Grazehell is offline  
Reply With Quote
#25  

:ninja:
My cooter sweats, and reeks like rotting sea vermon.
 
:ninja:'s Avatar
 
Quote:
Originally Posted by aoeoae View Post
i wonder if he's using deitel. i felt like i was wasting my time with C++ until i switched to much more concise book (accelerated C++, koenig & moo). then i switched to a more concise language, python

Mmm... Python. Isn't that the language where you take 100 programmers and give them a problem to solve, and all 100 programs are identical?
__________________
Use Linux and BSD
Old 04-29-2012, 01:51 PM :ninja: is offline  
Reply With Quote
#26  

:ninja:
My cooter sweats, and reeks like rotting sea vermon.
 
:ninja:'s Avatar
 
Quote:
Originally Posted by Grazehell View Post
The book is fine. But you really can't expect me to learn everything from reading a book?
No, you're doing it right. You need to write programs and solve problems to get better at writing programs and solving problems. Not using strtoul with base 2 to convert strings of binary is a good exercise. An even better exercise, however, would be to write your own strtoul. Check out the source code from any free strtoul implementation and understand how it works. This is why developing for Linux and BSD is so useful... you're not using some hidden and poorly-documented API which is subject to change between releases.

I would argue that C++ is a silly language and is difficult to learn as an introduction to programming. The language provides so many "features" and some C++ developers get the idea that they need to use all of them in every program they write. Even worse, you get companies that only use a subset of C++ features, for the same reason.

With the things you are trying to learn right now, I would suggest you pick up K&R C. It is short, concise, and infinitely useful. Trying to toss in all the silly features of C++ and OOP when you're just trying to learn the basics is counterintuitive.


Also, operator overloading is the fucking devil.
__________________
Use Linux and BSD
Old 04-29-2012, 02:02 PM :ninja: is offline  
Reply With Quote
#27  

Jehannum
 
Jehannum's Avatar
 
Quote:
Originally Posted by :ninja: View Post
No, you're doing it right. You need to write programs and solve problems to get better at writing programs and solving problems. Not using strtoul with base 2 to convert strings of binary is a good exercise. An even better exercise, however, would be to write your own strtoul. Check out the source code from any free strtoul implementation and understand how it works. This is why developing for Linux and BSD is so useful... you're not using some hidden and poorly-documented API which is subject to change between releases.

I would argue that C++ is a silly language and is difficult to learn as an introduction to programming. The language provides so many "features" and some C++ developers get the idea that they need to use all of them in every program they write. Even worse, you get companies that only use a subset of C++ features, for the same reason.

With the things you are trying to learn right now, I would suggest you pick up K&R C. It is short, concise, and infinitely useful. Trying to toss in all the silly features of C++ and OOP when you're just trying to learn the basics is counterintuitive.


Also, operator overloading is the fucking devil.

I occasionally reference that book to this day ('course, I work in C, not C++). I've had it since 1996, I think.

Ad hoc polymorphism is proper OOP design, IMO. Of course, badly done overloading takes away from it.
__________________
Your powers are useless! I'm wearing my tin foil underwear!

1992 300ZX: Not stock, 433 RWHP
1971 240Z: Toyota front brakes, 123 RWHP
1967 Pontiac GTO: not stock.
Old 04-29-2012, 07:26 PM Jehannum is offline  
Reply With Quote
#28  

Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -7. The time now is 12:03 AM.



Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.