Not Yet Answered # counting digits

Ancient Dragon 5,243 Dani 1,477 Ancient Dragon 5,243 Ryu vov4ik Ryu Purple Avenger 18 Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

create a loop that repeatedly divides the value by 10 until its value becomes 0. increment a counter on each loop iteration. see the description for the idiv instruction if you do not know what it does.

0

You would need to convert the binary number to an integer first for that though, wouldn't you?

0

You would need to convert the binary number to an integer first for that though, wouldn't you?

binary numbers are either signed or unsigned integers. No conversion necessary.

0

Does anyone knows how can I count how many digits are there in a binary number? Any ideas???

From what I understand, you want to count the number of digits in binary form, ex. 10001 (decimal 17) has 5 digits. You simply test the most significant towards least significant bits untill you reach a bit that is set on or 1. Total bits minus that count is the number of digits, example would be a 16bit register and a 0000000000010001 binary will give you 11 as your count (as theres 11 zeros). So 16-11 = 5. If you want the number of digits in base 10 then refer to the previous posts.

0

From what I understand, you want to count the number of digits in binary form, ex. 10001 (decimal 17) has 5 digits. You simply test the most significant towards least significant bits untill you reach a bit that is set on or 1. Total bits minus that count is the number of digits, example would be a 16bit register and a 0000000000010001 binary will give you 11 as your count (as theres 11 zeros). So 16-11 = 5. If you want the number of digits in base 10 then refer to the previous posts.

How do i test the most/last significant bits of register?

In a general, is there list of all assembly functions available somewhere on web, i haven't found one ?

0

How do i test the most/last significant bits of register?

In a general, is there list of all assembly functions available somewhere on web, i haven't found one ?

You use the TEST instruction, I'm assuming that you are working with IA32 architecture.

Example:

```
mov ax, myBinaryValue
mov dx, 0000000000000001b ; first ROR will make this most significant bit
mov cx, 16 ; 16 bits
LOOP:
ror dx, 1 ; rotate bits to the right by 1
test dx, ax ; this test will set ZF=0 (not zero) when the a bit is found on
jnz BITFOUND
dec cx ; decrease bit count
jnz LOOP ; test again
;;;; if program enters here myBinaryValue is zero ;;;;
BITFOUND:
;;;; if program enters here a bit set on was found ;;;;
;;;; number of digits should be in CX register ;;;
```

Note: this program was never tested.

0

```
;
; Assuming 386 32 bit assembler code
;
mov ecx,val
xor eax,eax ; Counts the number of '1' bits
again:
shl ecx,1
adc eax,0
or ecx,ecx
jnz again
done:
;
; EAX has the count of bits in "val"
;
```

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...