[H-GEN] Conversion of Integer to Binary
Anthony Towns
aj at humbug.org.au
Thu Oct 30 23:04:18 EST 1997
-----BEGIN PGP SIGNED MESSAGE-----
On Fri, 31 Oct 1997, Cameron Reeves wrote:
> There is probably a really easy answer to this, but is there an escape
> sequence that exists that allows an integer value to be printed out in
> binary? I am thinking along the lines of the octal and hex sequences. Is
> there one that exists, or do I have to manually write the code for it?
] [aj at azure ~]$ cat tobin.sh
] #!/bin/sh
] for n in $@; do
] printf "%o\n" $n | sed "s/0/000/g;s/1/001/g;s/2/010/g;s/3/011/g" |
] sed "s/4/100/g;s/5/101/g;s/6/110/g;s/7/111/g" | sed "s/^0*/0/g;s/^01/1/g"
] done
] [aj at azure ~]$ ./tobin.sh -1 0 1 2 3 4 5
] 11111111111111111111111111111111
] 0
] 1
] 10
] 11
] 100
] 101
] [aj at azure ~]$ _
Hope this helps.
Cheers,
aj (and yes, there probably _is_ an easy solution)
- --
Anthony Towns <aj at humbug.org.au> <http://student.uq.edu.au/~s343676/>
I don't speak for anyone save myself. PGP encrypted mail preferred.
``NT, Networking, Security. Pick any two (you can't have all three).''
-- _The Twelve Networking Truths_, RFC 1925, paraphrased
-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: ascii
Comment: Key available at http://student.uq.edu.au/~s343676/aj_key.asc
iQCVAwUBNFlYx+RRvX9xctrtAQENMAP/b9urHCvVE90oTblra1SnmYZY0BR2+XJ+
45F7Uml9JYEQkBUM4O8vPws+FwrINkYqzsxvyv5uuqYKuq8qdD8yMJVpRylPIXGQ
8MZF5daTN9L8OiJ27AtJjoV5uRY/sl8BGVLoxbkygFGrWWgxyLKLuPpGnHVaJJLO
7XwVVwRHgtw=
=37hl
-----END PGP SIGNATURE-----
----------------------- HUMBUG General List --------------------------------
echo "unsubscribe general" | mail majordomo at humbug.org.au # To Unsubscribe
More information about the General
mailing list