-1

This question is based on computer system pep/9 and I need someone to explain how can I convert this -8.75 number to binary.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
K.Tumba
  • 31
  • 2
  • 4
    and what have you tried? – phuclv Oct 23 '20 at 04:35
  • 1
    Related: [If the floating-point number storage on a certain system has a sign bit, a 3-bit exponent, and a 4-bit significand:](https://stackoverflow.com/q/59914695) shows some example encodings for that format. – Peter Cordes Oct 23 '20 at 04:51
  • Also related: [Exponent out of range: convert positive decimal number into floating point 3 bits exponent 5 bits mantissa format](https://stackoverflow.com/q/34977664) has some info and links in the question for a 3-bit exponent / 4-bit mantissa (significand) – Peter Cordes Oct 23 '20 at 04:57
  • "three-bit exponent field and four-bit significand" is not enough information here. There are many possible format choices that could fit that description. What other information do you have about the format? Any example values and corresponding bit patterns? – Mark Dickinson Oct 23 '20 at 12:53
  • @MarkDickinson: I think these days in basic homework questions, we should assume IEEE-754 rules for binary floating point, i.e. biased exponent representing 2^e. No CPU architectures use anything else. Although you're right, the OP really should have specified that; I added that tag. I didn't look up the pep/9 ISA to find out if it has an FPU, and if that FPU uses IEEE-style floats. – Peter Cordes Oct 23 '20 at 23:47
  • @PeterCordes: Agreed that "IEEE 754-like" is likely a safe assumption, but unfortunately it's not enough: there's a wealth of variations on the IEEE 754 theme appearing in textbooks. It's unlikely that the OP has access to a detailed specification, but a couple of examples would help address possible ambiguities (is this precision 5 with a hidden bit or precision 4? Is the bias -2 as chux suggests, or -3, which would be more in keeping with the IEEE 754 pattern; is there an exponent reserved for infinities and nans or not?). – Mark Dickinson Oct 24 '20 at 07:06
  • @MarkDickinson: https://en.wikipedia.org/wiki/IEEE_754#Formats has 3 free parameters: radix, precision, and exponent-range. So yes, fair point, you could choose your bias. All IEEE formats can encode NaN and +-Inf, though; without that it's only IEEE-754-like, not actually following it. I thought actual 754 would be a safe-ish assumption. But yeah, I guess 754 leaves enough encoding details unspecified that the OP's parameters don't uniquely identify an encoding, especially the implicit 1 bit or not. – Peter Cordes Oct 24 '20 at 07:17
  • It can't be _actual_ IEEE 754: IEEE 754 specifies parameters of interchange formats only for specific bit sizes (for binary: 16-bit, 32-bit, 64-bit, 128-bit and multiples of 32 bits larger than 128). (See section 3.6 of IEEE 754-2019.) – Mark Dickinson Oct 24 '20 at 07:19

1 Answers1

3

"-8.75" decimal is "-1000.11" binary. With four-bit significand, some rounding needs to occur.

   -8.75       decimal
-1000.11  *2^0 binary
-1001.    *2^0 rounded to 4 bit significand
   -1.001 *2^3 Exponent shift

Changing the significand to the encoded one where the leading bit is implied would imply a 5-bit significant (4 bits encoded).

-1001.0   *2^0 rounded to 5 bit significand
   -1.0010*2^3 Exponent shift
   -x.0010*2^3 Implied one bit

OP is not clear about what exponent bias to use to encode, but I suspect the bias is -2.

   -x.0010*2^3 Implied one bit
   -x.0010*2^(1 - -2) Exponent Bias
   |  |  |    +---- Encoded Exponent
   |  +--+--------- Encoded significand
   +--------------- Sign
  
   1 001 0010 

Or look up "-9" in Minifloat

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256