Binary twos complement

Create issue
Issue #562 new
Former user created an issue

Originally reported on Google Code with ID 562

I think SpeedCrunch is a fantastic tool and I use i daily at work. As a hardware (FPGA)
designer I just love the hexadecimal and binary formats and the easy-to-use conversion
functions. The only problem is that in hardware, negative binary numbers are represented
using two's complement. So when I copy data from a simulation for verification I have
to convert them manually before using speedcrunch.

Speedcrunch uses the following notation: bin(-2) -> -0b010. 
With twos complement the result would be twos(-2) -> 0t110.

To avoid confusion I think that a new function e.g. twos(N) and a new prefix should
be used. 

Best regards,
Anders Bergåker

Reported by anders.bergaker on 2015-05-05 10:32:49

Comments (7)

  1. Pol Welter

    You obviously need to know how many bits you want in total. In the development version you can define your own function. Something like twos(x; nbits) = bin(2^nbits+x) should do the job.

  2. flip -

    I'm also an FPGA/ASIC engineer looking for the same functionality. Is the 0t00 notation already available? I'm not sure if this notation was requested or the twos() function was requested. I use speedcrunch 0.11 where this is not available. Can i get a newer version or possibly do a source build for windows?

  3. Tey'

    The 0t notation is not available, but you can define user functions since 0.11, so just define the twos function by entering twos(x; nbits) = bin(2^nbits+x) in the formula prompt, and then you will be able to use it (e.g., twos(-2;3) for the OP example). If it doesn't work with 0.11, use the nightly build instead (the forthcoming 0.12 release will not contain much differences anyway).

  4. Log in to comment