How to represent a integer by a chain of 8 bit numbers [closed]
up vote
-2
down vote
favorite
I am wondering how you can represent an integer as a chain of 8-bit numbers.
That is, (and I don't know how to actually calculate this so the example is wrong, but should demonstrate the basic idea), say you have an integer of arbitrary size, meaning it can be extremely large like Math.pow(100, 100) ≈ 1e+200
or some small number like 1
or 0
. You want to be able to compute that number by using a chain of 8-bit values. The question is how to do that.
For example, I can represent 255
like this:
[ 255, 1 ]
That is, our representation has the first value be 8-bits, and then the second value is also 8-bits, and we multiply them together as 255 * 1 = 255
. Another case would be 256
. We could represent that like this:
[ 255, 1, 1 ]
Meaning (255 * 1) + 1 = 256
, but now we don't necessarily know what to add vs. what to multiply. Imagine a large number like 1589158915
. I have no idea what it's array of values would be, but say they ended up being like this:
[ 15, 12, 1, 141, 12, 250 ]
And say that from those numbers we could compute the value like this:
15 * 12 + 1 * 141 / 12 - 250
That wouldn't be very ideal, unless perhaps the system also stored the operation with the value, like this:
[ 15, 2, 12, 0, 1, 2, 141, 3, 12, 1, 250 ]
But I have no idea where to begin to figure out how to calculate the number like this, or how to say "given some integer, figure out how to break it apart into some equation that will generate its value, where each value in the equation is an integer". That is the basis of the question. I guess (actually) this would probably be the best approach.
As a sidenote, you can't take the integer 1589158915
and just represent it like this:
[ 1589158914, 1 ] == (1589158914 + 1)
because 1589158915
is not an 8-bit value. This is why it's tricky. In addition, we don't want to do it like this:
[ 255, 255, 255, 255, ... ]
==
255 + 255 + 255 + 255 + ...
Because that would be very inefficient. The solution should be a compact representation.
So the question is, how to take an integer and create an equation from it that will generate its value, where each component of the equation can be represented as an 8-bit integer. Wondering what the general technique is for doing this with any arbitrary integer.
integers
closed as unclear what you're asking by gammatester, KReiser, Chinnapparaj R, Shailesh, user10354138 Nov 22 at 2:51
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
-2
down vote
favorite
I am wondering how you can represent an integer as a chain of 8-bit numbers.
That is, (and I don't know how to actually calculate this so the example is wrong, but should demonstrate the basic idea), say you have an integer of arbitrary size, meaning it can be extremely large like Math.pow(100, 100) ≈ 1e+200
or some small number like 1
or 0
. You want to be able to compute that number by using a chain of 8-bit values. The question is how to do that.
For example, I can represent 255
like this:
[ 255, 1 ]
That is, our representation has the first value be 8-bits, and then the second value is also 8-bits, and we multiply them together as 255 * 1 = 255
. Another case would be 256
. We could represent that like this:
[ 255, 1, 1 ]
Meaning (255 * 1) + 1 = 256
, but now we don't necessarily know what to add vs. what to multiply. Imagine a large number like 1589158915
. I have no idea what it's array of values would be, but say they ended up being like this:
[ 15, 12, 1, 141, 12, 250 ]
And say that from those numbers we could compute the value like this:
15 * 12 + 1 * 141 / 12 - 250
That wouldn't be very ideal, unless perhaps the system also stored the operation with the value, like this:
[ 15, 2, 12, 0, 1, 2, 141, 3, 12, 1, 250 ]
But I have no idea where to begin to figure out how to calculate the number like this, or how to say "given some integer, figure out how to break it apart into some equation that will generate its value, where each value in the equation is an integer". That is the basis of the question. I guess (actually) this would probably be the best approach.
As a sidenote, you can't take the integer 1589158915
and just represent it like this:
[ 1589158914, 1 ] == (1589158914 + 1)
because 1589158915
is not an 8-bit value. This is why it's tricky. In addition, we don't want to do it like this:
[ 255, 255, 255, 255, ... ]
==
255 + 255 + 255 + 255 + ...
Because that would be very inefficient. The solution should be a compact representation.
So the question is, how to take an integer and create an equation from it that will generate its value, where each component of the equation can be represented as an 8-bit integer. Wondering what the general technique is for doing this with any arbitrary integer.
integers
closed as unclear what you're asking by gammatester, KReiser, Chinnapparaj R, Shailesh, user10354138 Nov 22 at 2:51
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Can't you just represent it base $256$?
– vrugtehagel
Nov 21 at 22:30
I am not sure, it is difficult to think about. If you could it would be helpful to see how.
– Lance Pollard
Nov 21 at 22:33
Since the question's been put on hold, let me explain myself here. Representing a number base $m$ is writing it as $a_nx^n+a_{n-1}x^{n-1}+cdots+a_1x+a_0$, with all $a_i$ between $0$ and $x$, and then we write that number as $(a_na_{n-1}cdots a_1a_0)_m$. Just like we have $453=4cdot10^2+5cdot10+3$, and write it as $453$, we can do that base $256$, so we write for example $66051=1cdot256^2+2cdot256+3=(123)_{256}$. Then your arrays can just be the digits of your numbers, so for example $[a,b,c,d]$ would represent $acdot256^3+bcdot256^2+ccdot255+d$.
– vrugtehagel
Nov 22 at 10:42
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I am wondering how you can represent an integer as a chain of 8-bit numbers.
That is, (and I don't know how to actually calculate this so the example is wrong, but should demonstrate the basic idea), say you have an integer of arbitrary size, meaning it can be extremely large like Math.pow(100, 100) ≈ 1e+200
or some small number like 1
or 0
. You want to be able to compute that number by using a chain of 8-bit values. The question is how to do that.
For example, I can represent 255
like this:
[ 255, 1 ]
That is, our representation has the first value be 8-bits, and then the second value is also 8-bits, and we multiply them together as 255 * 1 = 255
. Another case would be 256
. We could represent that like this:
[ 255, 1, 1 ]
Meaning (255 * 1) + 1 = 256
, but now we don't necessarily know what to add vs. what to multiply. Imagine a large number like 1589158915
. I have no idea what it's array of values would be, but say they ended up being like this:
[ 15, 12, 1, 141, 12, 250 ]
And say that from those numbers we could compute the value like this:
15 * 12 + 1 * 141 / 12 - 250
That wouldn't be very ideal, unless perhaps the system also stored the operation with the value, like this:
[ 15, 2, 12, 0, 1, 2, 141, 3, 12, 1, 250 ]
But I have no idea where to begin to figure out how to calculate the number like this, or how to say "given some integer, figure out how to break it apart into some equation that will generate its value, where each value in the equation is an integer". That is the basis of the question. I guess (actually) this would probably be the best approach.
As a sidenote, you can't take the integer 1589158915
and just represent it like this:
[ 1589158914, 1 ] == (1589158914 + 1)
because 1589158915
is not an 8-bit value. This is why it's tricky. In addition, we don't want to do it like this:
[ 255, 255, 255, 255, ... ]
==
255 + 255 + 255 + 255 + ...
Because that would be very inefficient. The solution should be a compact representation.
So the question is, how to take an integer and create an equation from it that will generate its value, where each component of the equation can be represented as an 8-bit integer. Wondering what the general technique is for doing this with any arbitrary integer.
integers
I am wondering how you can represent an integer as a chain of 8-bit numbers.
That is, (and I don't know how to actually calculate this so the example is wrong, but should demonstrate the basic idea), say you have an integer of arbitrary size, meaning it can be extremely large like Math.pow(100, 100) ≈ 1e+200
or some small number like 1
or 0
. You want to be able to compute that number by using a chain of 8-bit values. The question is how to do that.
For example, I can represent 255
like this:
[ 255, 1 ]
That is, our representation has the first value be 8-bits, and then the second value is also 8-bits, and we multiply them together as 255 * 1 = 255
. Another case would be 256
. We could represent that like this:
[ 255, 1, 1 ]
Meaning (255 * 1) + 1 = 256
, but now we don't necessarily know what to add vs. what to multiply. Imagine a large number like 1589158915
. I have no idea what it's array of values would be, but say they ended up being like this:
[ 15, 12, 1, 141, 12, 250 ]
And say that from those numbers we could compute the value like this:
15 * 12 + 1 * 141 / 12 - 250
That wouldn't be very ideal, unless perhaps the system also stored the operation with the value, like this:
[ 15, 2, 12, 0, 1, 2, 141, 3, 12, 1, 250 ]
But I have no idea where to begin to figure out how to calculate the number like this, or how to say "given some integer, figure out how to break it apart into some equation that will generate its value, where each value in the equation is an integer". That is the basis of the question. I guess (actually) this would probably be the best approach.
As a sidenote, you can't take the integer 1589158915
and just represent it like this:
[ 1589158914, 1 ] == (1589158914 + 1)
because 1589158915
is not an 8-bit value. This is why it's tricky. In addition, we don't want to do it like this:
[ 255, 255, 255, 255, ... ]
==
255 + 255 + 255 + 255 + ...
Because that would be very inefficient. The solution should be a compact representation.
So the question is, how to take an integer and create an equation from it that will generate its value, where each component of the equation can be represented as an 8-bit integer. Wondering what the general technique is for doing this with any arbitrary integer.
integers
integers
edited Nov 21 at 22:15
asked Nov 21 at 22:09
Lance Pollard
1,123723
1,123723
closed as unclear what you're asking by gammatester, KReiser, Chinnapparaj R, Shailesh, user10354138 Nov 22 at 2:51
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by gammatester, KReiser, Chinnapparaj R, Shailesh, user10354138 Nov 22 at 2:51
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Can't you just represent it base $256$?
– vrugtehagel
Nov 21 at 22:30
I am not sure, it is difficult to think about. If you could it would be helpful to see how.
– Lance Pollard
Nov 21 at 22:33
Since the question's been put on hold, let me explain myself here. Representing a number base $m$ is writing it as $a_nx^n+a_{n-1}x^{n-1}+cdots+a_1x+a_0$, with all $a_i$ between $0$ and $x$, and then we write that number as $(a_na_{n-1}cdots a_1a_0)_m$. Just like we have $453=4cdot10^2+5cdot10+3$, and write it as $453$, we can do that base $256$, so we write for example $66051=1cdot256^2+2cdot256+3=(123)_{256}$. Then your arrays can just be the digits of your numbers, so for example $[a,b,c,d]$ would represent $acdot256^3+bcdot256^2+ccdot255+d$.
– vrugtehagel
Nov 22 at 10:42
add a comment |
1
Can't you just represent it base $256$?
– vrugtehagel
Nov 21 at 22:30
I am not sure, it is difficult to think about. If you could it would be helpful to see how.
– Lance Pollard
Nov 21 at 22:33
Since the question's been put on hold, let me explain myself here. Representing a number base $m$ is writing it as $a_nx^n+a_{n-1}x^{n-1}+cdots+a_1x+a_0$, with all $a_i$ between $0$ and $x$, and then we write that number as $(a_na_{n-1}cdots a_1a_0)_m$. Just like we have $453=4cdot10^2+5cdot10+3$, and write it as $453$, we can do that base $256$, so we write for example $66051=1cdot256^2+2cdot256+3=(123)_{256}$. Then your arrays can just be the digits of your numbers, so for example $[a,b,c,d]$ would represent $acdot256^3+bcdot256^2+ccdot255+d$.
– vrugtehagel
Nov 22 at 10:42
1
1
Can't you just represent it base $256$?
– vrugtehagel
Nov 21 at 22:30
Can't you just represent it base $256$?
– vrugtehagel
Nov 21 at 22:30
I am not sure, it is difficult to think about. If you could it would be helpful to see how.
– Lance Pollard
Nov 21 at 22:33
I am not sure, it is difficult to think about. If you could it would be helpful to see how.
– Lance Pollard
Nov 21 at 22:33
Since the question's been put on hold, let me explain myself here. Representing a number base $m$ is writing it as $a_nx^n+a_{n-1}x^{n-1}+cdots+a_1x+a_0$, with all $a_i$ between $0$ and $x$, and then we write that number as $(a_na_{n-1}cdots a_1a_0)_m$. Just like we have $453=4cdot10^2+5cdot10+3$, and write it as $453$, we can do that base $256$, so we write for example $66051=1cdot256^2+2cdot256+3=(123)_{256}$. Then your arrays can just be the digits of your numbers, so for example $[a,b,c,d]$ would represent $acdot256^3+bcdot256^2+ccdot255+d$.
– vrugtehagel
Nov 22 at 10:42
Since the question's been put on hold, let me explain myself here. Representing a number base $m$ is writing it as $a_nx^n+a_{n-1}x^{n-1}+cdots+a_1x+a_0$, with all $a_i$ between $0$ and $x$, and then we write that number as $(a_na_{n-1}cdots a_1a_0)_m$. Just like we have $453=4cdot10^2+5cdot10+3$, and write it as $453$, we can do that base $256$, so we write for example $66051=1cdot256^2+2cdot256+3=(123)_{256}$. Then your arrays can just be the digits of your numbers, so for example $[a,b,c,d]$ would represent $acdot256^3+bcdot256^2+ccdot255+d$.
– vrugtehagel
Nov 22 at 10:42
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
If you want to have a 1-to-1 representation of each integer with a sequence of 8-bit values, then there is no way to be consistently "compact" - this comes out of measure theory and it's the same reason that zipping a zip file doesn't usually reduce its size.
A quick sketch of why this is the case: there are 256 different 8-bit numbers. Therefore, you can represent at most 256 different values using them, and if you try to fit some larger numbers into this space then you must also skip over smaller numbers to do so, which will have to be represented with bigger values.
On a smaller scale, let's look at 2 bits. We have 00, 01, 10, and 11 that we can assign to 4 different values, so if we don't just pick 0, 1, 2 and 3 then at least one of those must be represented with more bits.
For different purposes you can choose representations that make certain purposes more efficient - for example, you can put information about the overall size of the value first, then put the finer details later, which might make it easier to compare values when you expect them to be very different.
If you are willing to lose some information, then you can "squeeze" values together somehow. This is the idea behind mantissa-exponent form: if you assume that after a few significant digits that the exact values don't really matter much, then you can just write numbers like $3.1 times 10^6$, or 3.1e6 as you would see in computational form.
I don't think he said the array had a maximum length though
– vrugtehagel
Nov 22 at 10:36
Hi didn't, but I was thinking more in terms of computers where referencing an object of arbitrary size can be difficult - you do essentially need to either say "this is how big the thing is" (which has limitations since you need to be able to express the size of things in the same way you express the things themselves, so what happens if the size of your object is larger than the biggest number you can store?) or you say "keep reading the array until you hit this value, which is the stopping point" (in which case you have to remove that value from the ones that you assign to actual values.
– ConMan
Nov 22 at 22:38
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
If you want to have a 1-to-1 representation of each integer with a sequence of 8-bit values, then there is no way to be consistently "compact" - this comes out of measure theory and it's the same reason that zipping a zip file doesn't usually reduce its size.
A quick sketch of why this is the case: there are 256 different 8-bit numbers. Therefore, you can represent at most 256 different values using them, and if you try to fit some larger numbers into this space then you must also skip over smaller numbers to do so, which will have to be represented with bigger values.
On a smaller scale, let's look at 2 bits. We have 00, 01, 10, and 11 that we can assign to 4 different values, so if we don't just pick 0, 1, 2 and 3 then at least one of those must be represented with more bits.
For different purposes you can choose representations that make certain purposes more efficient - for example, you can put information about the overall size of the value first, then put the finer details later, which might make it easier to compare values when you expect them to be very different.
If you are willing to lose some information, then you can "squeeze" values together somehow. This is the idea behind mantissa-exponent form: if you assume that after a few significant digits that the exact values don't really matter much, then you can just write numbers like $3.1 times 10^6$, or 3.1e6 as you would see in computational form.
I don't think he said the array had a maximum length though
– vrugtehagel
Nov 22 at 10:36
Hi didn't, but I was thinking more in terms of computers where referencing an object of arbitrary size can be difficult - you do essentially need to either say "this is how big the thing is" (which has limitations since you need to be able to express the size of things in the same way you express the things themselves, so what happens if the size of your object is larger than the biggest number you can store?) or you say "keep reading the array until you hit this value, which is the stopping point" (in which case you have to remove that value from the ones that you assign to actual values.
– ConMan
Nov 22 at 22:38
add a comment |
up vote
0
down vote
If you want to have a 1-to-1 representation of each integer with a sequence of 8-bit values, then there is no way to be consistently "compact" - this comes out of measure theory and it's the same reason that zipping a zip file doesn't usually reduce its size.
A quick sketch of why this is the case: there are 256 different 8-bit numbers. Therefore, you can represent at most 256 different values using them, and if you try to fit some larger numbers into this space then you must also skip over smaller numbers to do so, which will have to be represented with bigger values.
On a smaller scale, let's look at 2 bits. We have 00, 01, 10, and 11 that we can assign to 4 different values, so if we don't just pick 0, 1, 2 and 3 then at least one of those must be represented with more bits.
For different purposes you can choose representations that make certain purposes more efficient - for example, you can put information about the overall size of the value first, then put the finer details later, which might make it easier to compare values when you expect them to be very different.
If you are willing to lose some information, then you can "squeeze" values together somehow. This is the idea behind mantissa-exponent form: if you assume that after a few significant digits that the exact values don't really matter much, then you can just write numbers like $3.1 times 10^6$, or 3.1e6 as you would see in computational form.
I don't think he said the array had a maximum length though
– vrugtehagel
Nov 22 at 10:36
Hi didn't, but I was thinking more in terms of computers where referencing an object of arbitrary size can be difficult - you do essentially need to either say "this is how big the thing is" (which has limitations since you need to be able to express the size of things in the same way you express the things themselves, so what happens if the size of your object is larger than the biggest number you can store?) or you say "keep reading the array until you hit this value, which is the stopping point" (in which case you have to remove that value from the ones that you assign to actual values.
– ConMan
Nov 22 at 22:38
add a comment |
up vote
0
down vote
up vote
0
down vote
If you want to have a 1-to-1 representation of each integer with a sequence of 8-bit values, then there is no way to be consistently "compact" - this comes out of measure theory and it's the same reason that zipping a zip file doesn't usually reduce its size.
A quick sketch of why this is the case: there are 256 different 8-bit numbers. Therefore, you can represent at most 256 different values using them, and if you try to fit some larger numbers into this space then you must also skip over smaller numbers to do so, which will have to be represented with bigger values.
On a smaller scale, let's look at 2 bits. We have 00, 01, 10, and 11 that we can assign to 4 different values, so if we don't just pick 0, 1, 2 and 3 then at least one of those must be represented with more bits.
For different purposes you can choose representations that make certain purposes more efficient - for example, you can put information about the overall size of the value first, then put the finer details later, which might make it easier to compare values when you expect them to be very different.
If you are willing to lose some information, then you can "squeeze" values together somehow. This is the idea behind mantissa-exponent form: if you assume that after a few significant digits that the exact values don't really matter much, then you can just write numbers like $3.1 times 10^6$, or 3.1e6 as you would see in computational form.
If you want to have a 1-to-1 representation of each integer with a sequence of 8-bit values, then there is no way to be consistently "compact" - this comes out of measure theory and it's the same reason that zipping a zip file doesn't usually reduce its size.
A quick sketch of why this is the case: there are 256 different 8-bit numbers. Therefore, you can represent at most 256 different values using them, and if you try to fit some larger numbers into this space then you must also skip over smaller numbers to do so, which will have to be represented with bigger values.
On a smaller scale, let's look at 2 bits. We have 00, 01, 10, and 11 that we can assign to 4 different values, so if we don't just pick 0, 1, 2 and 3 then at least one of those must be represented with more bits.
For different purposes you can choose representations that make certain purposes more efficient - for example, you can put information about the overall size of the value first, then put the finer details later, which might make it easier to compare values when you expect them to be very different.
If you are willing to lose some information, then you can "squeeze" values together somehow. This is the idea behind mantissa-exponent form: if you assume that after a few significant digits that the exact values don't really matter much, then you can just write numbers like $3.1 times 10^6$, or 3.1e6 as you would see in computational form.
edited Nov 21 at 23:00
answered Nov 21 at 22:52
ConMan
7,4021324
7,4021324
I don't think he said the array had a maximum length though
– vrugtehagel
Nov 22 at 10:36
Hi didn't, but I was thinking more in terms of computers where referencing an object of arbitrary size can be difficult - you do essentially need to either say "this is how big the thing is" (which has limitations since you need to be able to express the size of things in the same way you express the things themselves, so what happens if the size of your object is larger than the biggest number you can store?) or you say "keep reading the array until you hit this value, which is the stopping point" (in which case you have to remove that value from the ones that you assign to actual values.
– ConMan
Nov 22 at 22:38
add a comment |
I don't think he said the array had a maximum length though
– vrugtehagel
Nov 22 at 10:36
Hi didn't, but I was thinking more in terms of computers where referencing an object of arbitrary size can be difficult - you do essentially need to either say "this is how big the thing is" (which has limitations since you need to be able to express the size of things in the same way you express the things themselves, so what happens if the size of your object is larger than the biggest number you can store?) or you say "keep reading the array until you hit this value, which is the stopping point" (in which case you have to remove that value from the ones that you assign to actual values.
– ConMan
Nov 22 at 22:38
I don't think he said the array had a maximum length though
– vrugtehagel
Nov 22 at 10:36
I don't think he said the array had a maximum length though
– vrugtehagel
Nov 22 at 10:36
Hi didn't, but I was thinking more in terms of computers where referencing an object of arbitrary size can be difficult - you do essentially need to either say "this is how big the thing is" (which has limitations since you need to be able to express the size of things in the same way you express the things themselves, so what happens if the size of your object is larger than the biggest number you can store?) or you say "keep reading the array until you hit this value, which is the stopping point" (in which case you have to remove that value from the ones that you assign to actual values.
– ConMan
Nov 22 at 22:38
Hi didn't, but I was thinking more in terms of computers where referencing an object of arbitrary size can be difficult - you do essentially need to either say "this is how big the thing is" (which has limitations since you need to be able to express the size of things in the same way you express the things themselves, so what happens if the size of your object is larger than the biggest number you can store?) or you say "keep reading the array until you hit this value, which is the stopping point" (in which case you have to remove that value from the ones that you assign to actual values.
– ConMan
Nov 22 at 22:38
add a comment |
1
Can't you just represent it base $256$?
– vrugtehagel
Nov 21 at 22:30
I am not sure, it is difficult to think about. If you could it would be helpful to see how.
– Lance Pollard
Nov 21 at 22:33
Since the question's been put on hold, let me explain myself here. Representing a number base $m$ is writing it as $a_nx^n+a_{n-1}x^{n-1}+cdots+a_1x+a_0$, with all $a_i$ between $0$ and $x$, and then we write that number as $(a_na_{n-1}cdots a_1a_0)_m$. Just like we have $453=4cdot10^2+5cdot10+3$, and write it as $453$, we can do that base $256$, so we write for example $66051=1cdot256^2+2cdot256+3=(123)_{256}$. Then your arrays can just be the digits of your numbers, so for example $[a,b,c,d]$ would represent $acdot256^3+bcdot256^2+ccdot255+d$.
– vrugtehagel
Nov 22 at 10:42