Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How do I convert from decimal to 2's Complement

by I0 (Priest)
on Apr 08, 2002 at 06:14 UTC ( #157371=note: print w/replies, xml ) Need Help??


in reply to How do I convert from decimal to 2's Complement

sub dec_bin2s { return unpack "B8", pack "c", shift; }

Replies are listed 'Best First'.
Re: Re: How do I convert from decimal to 2's Complement
by mdillon (Priest) on Apr 08, 2002 at 06:34 UTC
    This one is correct (as I'm sure I0 knows).

    From perldoc -f pack:

    c   A signed char value.
    ...
    i   A signed integer value.
        (This 'integer' is at least 32 bits wide.  Its exact
        size depends on what a local C compiler calls 'int',
        and may even be larger than the 'long' described in
        the next item.)
    
    The question asks specifically for signed 8-bit, which is "c", a signed char value (8 bits). "At least 32 bits" is not 8 bits.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://157371]
help
Chatterbox?
[Happy-the-monk]: LanX; you did?
[Discipulus]: ah! plastering thanks..
[LanX]: I'd need english subtitles ... like with most English speaking movies...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2018-02-19 10:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (262 votes). Check out past polls.

    Notices?