Binary twos complement
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)
-
-
- marked as enhancement
- edited description
-
repo owner -
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?
-
repo owner The latest available Windows build is always available here.
-
I tried the latest version, it doesn't recognize the 0t01 notation :(
-
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). - Log in to comment
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.