🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Tom Cunningham Wed, 05 Nov 1986 22:44
Finding MSB in bit string
#9728
Author: 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads