As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

Binary Woes

ÆthelredÆthelred Registered User regular
edited October 2009 in Help / Advice Forum
This is really going to look like a homework question, but I swear 'tisn'.t.

I'm looking at a past exam paper for Computer Science and the question is thus:

"Show how it is possible to represent the decimal number 1024 as an 8 bit binary number."

Now, to me, this seems impossible. 1024 in binary is: 0100 0000 0000 .. and that needs 11 bits. I don't see how to express the number in a lower amount of bits. Is it something to do with floating points..?

pokes: 1505 8032 8399
Æthelred on

Posts

  • Options
    jclastjclast Registered User regular
    edited October 2009
    There is no reason that you couldn't store it as 0100 0000 as long as whatever is accessing it knows to multiply the stored value by 0001 0000 when it needs to use the value. Of course you lose precision this way (can only store multiples of 16), but I can't see any other way to do it.

    jclast on
    camo_sig2.png
  • Options
    ÆthelredÆthelred Registered User regular
    edited October 2009
    That's a solution, yeah. It's hard to know where the question is coming from. I'm not sure if that would be an acceptable answer or not. You could just as well say "have a program set to interpret 0001 as 1024", surely.

    Æthelred on
    pokes: 1505 8032 8399
  • Options
    GothicLargoGothicLargo Registered User regular
    edited October 2009
    Æthelred wrote: »
    This is really going to look like a homework question, but I swear 'tisn'.t.

    I'm looking at a past exam paper for Computer Science and the question is thus:

    "Show how it is possible to represent the decimal number 1024 as an 8 bit binary number."

    Now, to me, this seems impossible. 1024 in binary is: 0100 0000 0000 .. and that needs 11 bits. I don't see how to express the number in a lower amount of bits. Is it something to do with floating points..?

    You are obviously correct that in a flat binary tally, it is impossible to count to 1024 in 8 bits. So in some sense you will need to think like a cheater.

    No, I'd instead say that there exists in memory an array of length <=256 which contains 32 bit numbers and that 1024 is in that array. The 8 bit number X is the index number which points to 1024 in that array. Boom, you've just "represented" 1024 using 8 bits by saying that the representation is a pointer.


    "By putting it in 8-bit addressed memory."

    GothicLargo on
    atfc.jpg
  • Options
    ÆthelredÆthelred Registered User regular
    edited October 2009
    Ah, that's quite cunning. Again, though, I'm not sure if it'd be allowed.. this isn't a programming paper; the question is surrounded by simple "convert to two's complement" questions and so on. It's possible it's a semi-trick question, but that'd be kind of a dick move for question 1b on an entry-level paper.

    I think I will have to see if I can get the "approved" answer to clear this up. Thanks.

    edit:
    It's to do with the use of scientific notation in computers (as in 6.022*10^23).

    Æthelred on
    pokes: 1505 8032 8399
  • Options
    ClipseClipse Registered User regular
    edited October 2009
    Æthelred wrote: »
    Ah, that's quite cunning. Again, though, I'm not sure if it'd be allowed.. this isn't a programming paper; the question is surrounded by simple "convert to two's complement" questions and so on. It's possible it's a semi-trick question, but that'd be kind of a dick move for question 1b on an entry-level paper.

    I think I will have to see if I can get the "approved" answer to clear this up. Thanks.

    edit:
    It's to do with the use of scientific notation in computers (as in 6.022*10^23).

    In a semi-scientific-notation style you could, for instance, use 4 bits as an exponent (of 2) and the other 4 as the value. So, for instance, if the second 4 bits are the exponent, 1024 would be 0001 1010, since it is 1*2^10. It's kind of an open-ended question with the value they chose, since you could just as easily have used 5, 6, 7, or even 8 bits for the exponent.

    Clipse on
  • Options
    PeregrineFalconPeregrineFalcon Registered User regular
    edited October 2009
    Clipse wrote: »
    Æthelred wrote: »
    Ah, that's quite cunning. Again, though, I'm not sure if it'd be allowed.. this isn't a programming paper; the question is surrounded by simple "convert to two's complement" questions and so on. It's possible it's a semi-trick question, but that'd be kind of a dick move for question 1b on an entry-level paper.

    I think I will have to see if I can get the "approved" answer to clear this up. Thanks.

    edit:
    It's to do with the use of scientific notation in computers (as in 6.022*10^23).

    In a semi-scientific-notation style you could, for instance, use 4 bits as an exponent (of 2) and the other 4 as the value. So, for instance, if the second 4 bits are the exponent, 1024 would be 0001 1010, since it is 1*2^10. It's kind of an open-ended question with the value they chose, since you could just as easily have used 5, 6, 7, or even 8 bits for the exponent.

    Or you could store it as (first four bits)^(last four bits) and get 0010 1010 (2^10)

    Or get bitwise on them and write it as 0100 0000 << 4

    PeregrineFalcon on
    Looking for a DX:HR OnLive code for my kid brother.
    Can trade TF2 items or whatever else you're interested in. PM me.
  • Options
    ClipseClipse Registered User regular
    edited October 2009
    Clipse wrote: »
    Æthelred wrote: »
    Ah, that's quite cunning. Again, though, I'm not sure if it'd be allowed.. this isn't a programming paper; the question is surrounded by simple "convert to two's complement" questions and so on. It's possible it's a semi-trick question, but that'd be kind of a dick move for question 1b on an entry-level paper.

    I think I will have to see if I can get the "approved" answer to clear this up. Thanks.

    edit:
    It's to do with the use of scientific notation in computers (as in 6.022*10^23).

    In a semi-scientific-notation style you could, for instance, use 4 bits as an exponent (of 2) and the other 4 as the value. So, for instance, if the second 4 bits are the exponent, 1024 would be 0001 1010, since it is 1*2^10. It's kind of an open-ended question with the value they chose, since you could just as easily have used 5, 6, 7, or even 8 bits for the exponent.

    Or you could store it as (first four bits)^(last four bits) and get 0010 1010 (2^10)

    Or get bitwise on them and write it as 0100 0000 << 4

    Yeah there is basically an infinite* number of ways to solve the problem, but with the scientific notation hint I'd imagine they're trying to make it vaguely similar to how floating point data is stored.

    * - Ok, 256 ways, but with infinitely many explanations.

    Clipse on
  • Options
    PeregrineFalconPeregrineFalcon Registered User regular
    edited October 2009
    Clipse wrote: »
    Yeah there is basically an infinite* number of ways to solve the problem, but with the scientific notation hint I'd imagine they're trying to make it vaguely similar to how floating point data is stored.

    * - Ok, 256 ways, but with infinitely many explanations.

    This made me chuckle. They're probably just trying to see how you'll answer it, and any of them will be perfectly valid.

    Dick answer follows:
    You could say that x is 0100, and your program automatically bitshifts everything left by itself twice. :P

    PeregrineFalcon on
    Looking for a DX:HR OnLive code for my kid brother.
    Can trade TF2 items or whatever else you're interested in. PM me.
Sign In or Register to comment.