Twos Complement
|
02-14-2023, 10:09 PM
(This post was last modified: 02-14-2023 10:17 PM by akmarul.)
Post: #1
|
|||
|
|||
Twos Complement
Hello all. I am quite comfortable to change between bases (eg, dec hex and etc). But I am still scratching my head, how to convert negative decimal to hex or binary. For example, if decimal is -5, then hex should give me FB. How do I do this in HP Prime? Or maybe my hex number if FB (a twos complement number), and how do I convert that to negative decimal?
|
|||
02-15-2023, 07:58 AM
Post: #2
|
|||
|
|||
RE: Twos Complement
Note that two's complement conventionally needs a particular finite word width: -5 is hex FB only for an 8 bit word. Otherwise, it might be FFFFFFFB, or FFFB, or even B, among many other possibilities. (The same is true for one's complement.)
Possibly the question is how to set the word width for binary or decimal numbers on the Prime... and I don't know the answer to that one. |
|||
02-15-2023, 08:36 AM
Post: #3
|
|||
|
|||
RE: Twos Complement
(02-15-2023 07:58 AM)EdS2 Wrote: Possibly the question is how to set the word width for binary or decimal numbers on the Prime... and I don't know the answer to that one. Binary integer settings can be controlled via these system variables: Bits := x, where 1≤x≤64, sets the binary integer word size. Signed := 0 for unsigned (default) Signed := 1 for signed Base := 0 for binary Base := 1 for octal Base := 2 for decimal Base := 3 for hexadecimal (default) N.B. All of the above info is in the built-in Help system. Press Vars, [Home], Settings, Integer, then press Help after highlighting Base or Bits or Signed. <0|ɸ|0> -Joe- |
|||
02-18-2023, 07:24 PM
(This post was last modified: 02-20-2023 05:48 PM by gehakte_bits.)
Post: #4
|
|||
|
|||
RE: Twos Complement
This might help, it follows mostly the traditional 2sC methods around..
(added save Signed state for those that use Signed, and crop to the requested bit width.) Code:
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)