#!/usr/bin/perl use strict; use warnings; #assume each value is a perl var masked to lower 8 bits foreach (0x85, 0x05) { my $x = $_; #allow mod of $x in loop my $neg = $x & 0x80; #decide if negative $x = ~$x & 0x7F if $neg; #adjust if so printf "%s%-08b%s%d\n",($neg)?"-":" ",$x,($neg)?"-":" ",$x; } __END__ -1111010 -122 101 5