Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!im4u!oakhill!tomc From: tomc@oakhill.UUCP (Tom Cunningham) Newsgroups: net.lang.c Subject: Finding MSB in bit string Message-ID: <800@oakhill.UUCP> Date: Wed, 5-Nov-86 17:44:00 EST Article-I.D.: oakhill.800 Posted: Wed Nov 5 17:44:00 1986 Date-Received: Wed, 5-Nov-86 22:49:52 EST Organization: Motorola Inc. Austin, Tx Lines: 26 Hopefully this won't get ignored after my last admittedly dumb posting (re: conversion in printf; thanks for the *civil* replies). I want to find the MSB in a bit string without having to do a series of shifts. Only the single bit in place needs to be isolated, to be used for example in a powers-of-2 switch. Finding the LSB in this way is no problem: unsigned i, t; t = -i; i &= t; switch (i) { case 1: case 2: case 4: case 8: . . . } Any equivalent way to do this to get the MSB? Tom Cunningham "Good, fast, cheap -- select two." USPS: Motorola Inc. 6501 William Cannon Dr. W. Austin, TX 78735-8598 UUCP: {ihnp4,seismo,ctvax,gatech}!ut-sally!oakhill!tomc Phone: 512-440-2953