Page 3 of 3

Re: std::string-to-int converter

Posted: Fri Jul 10, 2009 9:35 pm
by eatcomics
I agree completely! :)

Re: std::string-to-int converter

Posted: Fri Jul 10, 2009 10:04 pm
by Joeyotrevor
programmerinprogress wrote:
eatcomics wrote:Wow you guys, I like seeing this kind of stuff, I'm sick of the C++ "I need code help stuff" I want more low level! && Hardware! ;) Maybe the owners can make a few more dedicated threads wink wink...
yeah me too, i'm very much interested in the low-level stuff as a side-project type thing.

some times it's fun to mess around with 1's and 0's :)
I recommend learning Assembly if you haven't already. It's really fun and you really learn a lot about computers.

http://www.drpaulcarter.com/pcasm/index.php has a great, free, modern book on Assembly.

Assembly is fun to learn, but it is really a pain in the ass to actually make useful stuff in. ;)

Re: std::string-to-int converter

Posted: Fri Jul 10, 2009 11:01 pm
by eatcomics
It's cool I know quite a bit about assembly :) I think the other people do to...

Re: std::string-to-int converter

Posted: Sat Jul 11, 2009 1:48 am
by Netwatcher
Joeyotrevor wrote:
programmerinprogress wrote:
eatcomics wrote:Wow you guys, I like seeing this kind of stuff, I'm sick of the C++ "I need code help stuff" I want more low level! && Hardware! ;) Maybe the owners can make a few more dedicated threads wink wink...
yeah me too, i'm very much interested in the low-level stuff as a side-project type thing.

some times it's fun to mess around with 1's and 0's :)
I recommend learning Assembly if you haven't already. It's really fun and you really learn a lot about computers.

http://www.drpaulcarter.com/pcasm/index.php has a great, free, modern book on Assembly.

Assembly is fun, but it is really a pain in the ass to actually make useful stuff in. ;)
what assembly exactly?

Re: std::string-to-int converter

Posted: Sat Jul 11, 2009 2:23 pm
by programmerinprogress
It's a second generation programming language, they invented it back in the 60's to cut down on the alarming rate of nervous breakdowns that computer operators were sufferring from by tapping in 1's and 0's all day :lol:

But, being serious now, it's a form of programming language which uses mnemonics (aides to the memory) to carry out machine code instructions.

Until assembly came along, you were expected to flick switches on the front panel of your computer terminal, and that was fine for small programs, but as programs grew in size, so did the demand for languages that simplifed the understanding of code, thus assembly was born

In assembly, you spend most of your time either loading or storing numbers from different memory locations (wither registers in your CPU or memory in your computer), and then doing some arithmetic, such as adding, subtraction, multiplying and division, you also do bitwise operations on numbers such as AND, OR, NOT etc, oh and bit shifting.

you have branching statements which are the equivalents to if, else if and else, the way all of the things mentioned above are implemented into the assembler vary depending on the CPU architecture you use, the most straightforward one I've tried is Acorn RISC assembly on an Acorn Archemedies, it had 14 registers to mess around with, and the mnemonics it used were easy to understand, it was also 32-bit, so you could do quite a few operations without the monotomy of having to do several operations for multiplication, because there was a multiplication instruction, which took a few operands at once.

PS: i'm not expert by the way, i've only been introduced to assembly, I believe Gyro is a lot more acquainted with the assembler than me :lol:

Re: std::string-to-int converter

Posted: Sat Jul 11, 2009 2:28 pm
by Netwatcher
programmerinprogress wrote:It's a second generation programming language, they invented it back in the 60's to cut down on the alarming rate of nervous breakdowns that computer operators were sufferring from by tapping in 1's and 0's all day :lol:

But, being serious now, it's a form of programming language which uses mnemonics (aides to the memory) to carry out machine code instructions.

Until assembly came along, you were expected to flick switches on the front panel of your computer terminal, and that was fine for small programs, but as programs grew in size, so did the demand for languages that simplifed the understanding of code, thus assembly was born

In assembly, you spend most of your time either loading or storing numbers from different memory locations (wither registers in your CPU or memory in your computer), and then doing some arithmetic, such as adding, subtraction, multiplying and division, you also do bitwise operations on numbers such as AND, OR, NOT etc, oh and bit shifting.

you have branching statements which are the equivalents to if, else if and else, the way all of the things mentioned above are implemented into the assembler vary depending on the CPU architecture you use, the most straightforward one I've tried is Acorn RISC assembly on an Acorn Archemedies, it had 14 registers to mess around with, and the mnemonics it used were easy to understand, it was also 32-bit, so you could do quite a few operations without the monotomy of having to do several operations for multiplication, because there was a multiplication instruction, which took a few operands at once.

PS: i'm not expert by the way, I've only been introduced to assembly, I believe Gyro is a lot more acquainted with the assembler than me :lol:
:lol: I meant it quite literally;
Netwatcher wrote:What assembly exactly
.
As you know, assembly is a family of languages as in assembly 8086 and whatnot...
Co's most of them are a pain in the ass rather then "fun".(8086 got too many stuff going on because of it's "backwards compatibility" shit ...)

Anyway... I think some people might get edjucated by your post so meh... :)

Re: std::string-to-int converter

Posted: Fri Jul 17, 2009 6:28 pm
by MarauderIIC
programmerinprogress wrote:basically, chars can be any value from 0 to 255 (with it being an 8 bit number), each of these numbers represent a different action and/or character.

in ASCII, codes 48 to 57 represent the digits '0' to '9', what you have to do to convert these characters to digits is to turn the value 48 into 0, 49 into 1, 50 into 2 etc [using bitmasks]
...because subtracting 48 is simply too hard to understand :)

As for the floating-point numbers:

The number is always assumed to be "+1 point something times 2 to the (something minus 127) power". So with the exponent-mantissa notation that netwatcher posted,
Click here to see the hidden message (It might contain spoilers)
Image
, you take "1". You append the mantissa (binary decimal) to "1". You convert it the same way you do a decimal number. Recall, when you convert decimal numbers, that things like 0.4 are the same as 4 * 10^(-1).

So, a mantissa of
1100 0000 0000 0000 0000 000
is
1 * 2^(-1) + 1 * 2^(-2) + 0 * 2^(-3) + 0 * 2 ^ (-4) + .... + 0 * 2 ^ (-23)
Which is
1/2 + 1/4 + 0 + 0 + 0....
0.5 + 0.25
0.75

And since we make the assumption about "1", this means that the decimal that we multiply by "2 to the (something minus 127) power" is 1.75

Now we need the exponent part:
0000 0111
Which is
0 * 2^7 + 0 * 2^7 + 0 * 2^6 + ... + 0 * 2^3 + 1 * 2^2 + 1 * 2^1 + 1 * 2^0
= 0 + 0 + 0 + ... + 0 + 1*4 + 1*2 + 1*1 = 7

The exponent is assumed to be in (theExponent - 127) form, and so, the exponent is 7 - 127 = -120. And again, the number as a whole is "1 point something times 2 to the (something minus 127) power". So our number is "1 point 75 times 2 to the negative 120th power" and becomes 1.75 * 2(-120) which hopefully comes out to 1.316554 * 10^(-36), since that's what the solution is in the example image above.

In short, floating-point notation has some rules -- such as "we will subtract 127 from the exponent specified" and "make the leading digit in the decimal be 1" which allows it to represent numbers in its limited number of bits, and books seem to neglect mentioning these. All this conversion is one reason that accuracy can be lost when dealing with floating-points.