Sign extending a number of arbitrary width lazarus / 21-General ---------------------------------------------------------------------- MarkMLl · 2022-04-16 20:08 Between everything else, I'm knocking together a disassembler backend for my logic analyzer. Is there a standard function which will sign-extend an integer of arbitrary width (e.g. 12 bits) to an Int64? I'm obviously aware of resources like https://graphics.stanford.edu/~s eander/bithacks.html#VariableSignExtend but haven't investigated in detail yet. MarkMLl ---------------------------------------------------------------------- MathMan · 2022-04-17 09:20 Assuming you would like a cross-platform portable intrinsic (or similar) then not available afaik. Would have suggested the same as your link does. If inlined it should be reasonably fast. Cheers, MathMan ---------------------------------------------------------------------- MarkMLl · 2022-04-17 10:58 I was looking at it more from the POV of some obscure facility in the standard library... I ranted yesterday about the poor indexing. I've tentatively coded the algorithm from the link, but not yet tested it. In practice it will only be used in the comparatively few places where bits from an instruction or operand should be displayed as a signed offset; I find my pattern-matching interpreter is adequately fast even without packing the instructions to a binary form (i.e. which would use case-of-enumeration rather than case-of-string). MarkMLl ---------------------------------------------------------------------- Objector · 2022-04-18 14:36 Quote from: MarkMLl on April 16, 2022, 10:08:30 pmIs there a standard function which will sign-extend an integer of arbitrary width (e.g. 12 bits) to an Int64? I'm absolutely sure no Pascal standard function or procedure implements that functionality whatsoever.  As to whether it is implemented by any Free Pascal's extended Pascal or Object Pascal procedure or function, I'm not aware of. Quote from: MarkMLl on April 16, 2022, 10:08:30 pmI'm obviously aware of resources like https://graphics.stanford.edu/~seander/bithacks.html #VariableSignExtend but haven't investigated in detail yet. Thanks for sharing that link with us.