🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9728

Finding MSB in bit string

#9728
From: Tom Cunningham
Date: Wed, 05 Nov 1986 22:44
26 lines
1167 bytes
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
Technical Details
Message-ID: <800@oakhill.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!ut-sally!im4u!oakhill!tomc

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!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