Dismiss
The Prior Art Database and Publishing service will be updated on Sunday, February 25th, from 1-3pm ET. You may experience brief service interruptions during that time.
Browse Prior Art Database

# Counting 1's in a Register

IP.com Disclosure Number: IPCOM000074662D
Original Publication Date: 1971-May-01
Included in the Prior Art Database: 2005-Feb-23
Document File: 1 page(s) / 11K

IBM

## Related People

Scherr, AL: AUTHOR

## Abstract

If a binary number n is ANDed with a number n-1, the result will be the original number with the rightmost 1 bit removed. Use can be made of this property to solve the general problem of counting the number of 1 bits in a register and the specific problem of testing the contents of a register for no 1 bits, only a rightmost 1 bit, or more-than-one 1 bit conditions.

This text was extracted from a PDF file.
This is the abbreviated version, containing approximately 100% of the total text.

Page 1 of 1

Counting 1's in a Register

If a binary number n is ANDed with a number n-1, the result will be the original number with the rightmost 1 bit removed. Use can be made of this property to solve the general problem of counting the number of 1 bits in a register and the specific problem of testing the contents of a register for no 1 bits, only a rightmost 1 bit, or more-than-one 1 bit conditions.

In Basic Assembler Language, a program providing a solution to the specific problem is: LTR WORKR,R load n from R into work reg BC 8,ZERO branch if no ones, n = 0 BCTR WORKR,0 decrement work reg by 1 NR WORKR,R strip off rightmost 1 in n BC 8,ONE branch if now zero, n = 1 continue here for n > 1. A program to solve the general problem is: SR COUNTR,COUNTR zero counter - keep complemented LOOP LTR WORKR,R put n in work reg BC 8,OUT branches when zero BCTR WORKR,0 n-1 NR R,WORKR strip off a one BCT COUNTR,LOOP add 1 to 1's count (in complemented form) - always branches OUT LCR COUNTR,COUNTR recomplement count of 1's.

1