I started learning Assembly language from the book: Introduction to 80x86 Assembly Language and Computer Architecture
This is from the Representing Data in a Computer
We have looked at two schemes to represent numbers-
- by using binary integers (often expressed in hex) or
- by using ASCII codes.
However, these methods have two problems:
I didn't understand these problems.
1: the number of bits available for representing a number is limited, and
I didn't get this. What is he saying?
2: it is not clear how to represent a negative number.
fine
To solve the first representation problem mentioned above, you can simply include the code for a minus sign. For example, the ASCII codes for the four characters -817 are 2D (for minus), 38, 31, and 37.
I think its second representation problem
. But ok, I got it.
To solve the first problem, you could always agree to use a fixed number of bytes, perhaps padding on the left with ASCII codes for zeros or spaces.
I've no clue about what he wants to say. AS开发者_JAVA技巧CII codes for zeros or spaces.
??
Alternatively, you could use a variable number of bytes, but agree that the number ends with the last ASCII code for a digit, that is, terminating the string with a nondigit.
I didn't get a single word.
I don't know why. But I cannot understand what he is trying to say. Could any one explain this. (examples would be great)
Wow. I haven't read the book, but if your excerpts are accurate, I'm not sorry that I missed it.
Binary representation of numbers is limited by the number of bits used to represent the number. You could define a representation that uses an large or variable number of bits, though. You'd pad on the left with binary zeros (or ones in a two's complement representation of a negative number).
ASCII representation of numbers could be done as the book describes. The problem with ASCII is that manipulating the numbers is harder: Addition is fairly simple, but imagine what division would look like.
He is referring to two different ways to store an integer in memory. He suggests two methods:
- storing the number in the base that the computer internally uses
- storing the number as base 10 (the base humans use).
Clearly the first is better for performance, but all your questions seem to relate to the second form of storing numbers which is a very unusual method for a computer to use (but not unusual to see in human readable source files).
Ignoring method 1 and considering only method 2, he further splits this into two subcategories: fixed width and variable width. In fixed width, you choose some limit to the size, for example 10 digits, and pad with zeros if it is less. With this system 12345 would be represented as an ASCII string:
0000012345
With a variable length system, you choose some delimiter, for example semicolon. This allows you to store integers of any size:
12345;
Computers do not typically store numbers in this form internally. The integer operations that modern processors support all require numbers to be stored using the computer's default base. You can think of it as being binary or hexadecimal if you wish, but actually these are just more human ways to represent the data to make it easier for us to think about it. Typically modern computers operate on larger chunks of data, for example 32 bits at a time.
I can see why you're having trouble. I suggest you find another book. This one is very, very hard to interpret.
"the number of bits available for representing a number is limited"
How many bits in a binary number? 32? That's a limit.
"I've no clue about what he wants to say. ASCII codes for zeros or spaces."
The ASCII code for space in 0x20. The ASCII code for zero is 0x30
http://www.asciitable.com/
"To solve the first problem, you could always agree to use a fixed number of bytes, perhaps padding on the left with ASCII codes for zeros or spaces."
Does not make a lot of sense. The first problem is limitations. Assuming it's for the second problem, it's done like this:
0x30 0x30 0x37 == 7. Fixed length of 3, padded on the left with ASCII zeroes. This is the standard COBOL representation of numbers -- strings of characters padded on the left with leading zeroes. (COBOL often uses a trailing sign character).
"Alternatively, you could use a variable number of bytes, but agree that the number ends with the last ASCII code for a digit, that is, terminating the string with a nondigit."
The number 1,234,456,890,123 (quite a large number) could be
0x20 0x31 0x32 0x33 0x34 0x34 0x35 0x36 0x38 0x39 0x30 0x31 0x32 0x33 0x00
It has a leading space, making it positive. It ends with a non-digit (0x00).
Not an answer as such, just some advice which you may want to ignore. Supplement your reading with a trip to Wikipedia articles on IEEE 754 (floating-point number representation) and on BCD (binary-coded decimal -- not the same thing as your ASCII but another similar approach). These will throw light on the problems and some solutions to them.
To understand how computers manipulate data, we must first understand how computers represent data. To do this it is necessary to understand some key concepts: Number Base Decimal In the Decimal system (base 10) we would write the number 11. Binary In the Octal system (base 2) the alien would write 1011. Octal In the Binary system (base 8) the computer would use 13. Hexadecimal In the Hexadecimal system (base 16) the number would be B !
精彩评论