This no longer seems like a topic appropriate for TCLCORE, but rather belongs in comp lang tcl, stack overflow, or a comp sci 101 class.
Just sayin'
-Brian
> On Feb 1, 2017, at 8:17 AM, Peter S <pete...@gmail.com> wrote:> > FWIW, here is a C test program for 8-bit integer types:> > #include <stdio.h>> > void printbits (char c) {> int i; for (i=7; i>=0; i--)> printf("%c",(c >> i) & 1 ? '1' : '0');> printf("\n");> }> > main() {> unsigned char ua = 0xFF;> signed char sa = 0xFF;> unsigned char ub = 255;> signed char sb = 255;> unsigned char uc = -1;> signed char sc = -1;> > char *uas = "(unsigned char)0xFF";> char *ubs = "(unsigned char)255";> char *ucs = "(unsigned char)-1";> char *sas = "(signed char)0xFF";> char *sbs = "(signed char)255";> char *scs = "(signed char)-1";> > puts("Binary representation:");> printf(" %-20s: 0b", uas); printbits(ua);> printf(" %-20s: 0b", sas); printbits(sa);> printf(" %-20s: 0b", ubs); printbits(ub);> printf(" %-20s: 0b", sbs); printbits(sb);> printf(" %-20s: 0b", ucs); printbits(uc);> printf(" %-20s: 0b", scs); printbits(sc);> > puts("");> puts("Arithmetic equality:");> if (ua == sa) { printf(" %s == %s\n", uas, sas); }> if (ua == ub) { printf(" %s == %s\n", uas, ubs); }> if (ua == sb) { printf(" %s == %s\n", uas, sbs); }> if (ua == uc) { printf(" %s == %s\n", uas, ucs); }> if (ua == sc) { printf(" %s == %s\n", uas, scs); }> if (sa == ub) { printf(" %s == %s\n", sas, ubs); }> if (sa == sb) { printf(" %s == %s\n", sas, sbs); }> if (sa == uc) { printf(" %s == %s\n", sas, ucs); }> if (sa == sc) { printf(" %s == %s\n", sas, scs); }> }> > Program output:> > Binary representation:> (unsigned char)0xFF : 0b11111111> (signed char)0xFF : 0b11111111> (unsigned char)255 : 0b11111111> (signed char)255 : 0b11111111> (unsigned char)-1 : 0b11111111> (signed char)-1 : 0b11111111> > Arithmetic equality:> (unsigned char)0xFF == (unsigned char)255> (unsigned char)0xFF == (unsigned char)-1> (signed char)0xFF == (signed char)255> (signed char)0xFF == (signed char)-1> > ------------------------------------------------------------------------------> Check out the vibrant tech community on one of the world's most> engaging tech sites, SlashDot.org! http://sdm.link/slashdot> _______________________________________________> Tcl-Core mailing list> Tcl-...@lists.sourceforge.net> https://lists.sourceforge.net/lists/listinfo/tcl-core
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
Tcl-...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-core