News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Help needed [Logical operations]

Started by Aiva, October 26, 2007, 11:48:49 PM

Previous topic - Next topic

Aiva

Hallo,  I was trying to change case of character, but or'ing value doesn't work, as i have no clue why, i would be grateful for explaining me where the problem is....thanks in advance.

Program Charcon;
#include( "stdlib.hhf" );

begin Charcon;

    stdout.put("enter char string  ");
    stdin.flushInput();             

repeat

    stdin.getc();

  if( al >= 'a' ) then
   
        if( al <= 'z' ) then
       
           
           
            or( $60, al );   //let's say i want to change value in al from $41 ( %0100_0001) to $61 (%0110_0001) i tried oring with $20, $60, $61
                                            //but it doesn't really matter because all these values should work.
           
        endif;
       
    endif;

                   
    stdout.putc( al );             
    stdout.put( "=$" ,al,nl );     

until(stdin.eoln() );

end Charcon;

Evenbit

I think this is what you want:

program Charcon;
#include( "stdlib.hhf" );

begin Charcon;

    stdout.put("enter char string  ");
    stdin.flushInput();             

repeat

    stdin.getc();

    if( al >= 'A' ) then
   
        if( al <= 'Z' ) then
                 
            add( #32, al );
           
        endif;
       
    endif;

    stdout.putc( al );             
    stdout.put( "=$" ,al,nl );     

until(stdin.eoln() );

end Charcon;


Nathan.
http://nathancbaker.googlepages.com/home

Aiva

#2
this is supposed to be done with logical operations, and why it does not work? if you and it with 5f it changes all values to higher case, by the way adding value you suggest doesn't change chars to lower case as well, and outputs some weird chars when input is lower case char, when it should let them through.

EDIT: problem fixed

Evenbit

Use the truth tables as a guide to how the logical operators function.

The AND operator only outputs a 1 if both inputs are also 1.

# | 0  1
----------
0 | 0  0
1 | 0  1

The OR operator outputs a 1 if either of the inputs are 1.

# | 0  1
----------
0 | 0  1
1 | 1  1

The XOR operator only outputs a 1 if the inputs are different.

# | 0  1
----------
0 | 0  1
1 | 1  0

For *setting* or *clearing* bits, the most useful operation is the AND operator.  To demonstrate, we will restrict the number a bits to four.

Binary, Hex, Decimal
--------------------
0000 0 0
0001 1 1
0010 2 2
0011 3 3
0100 4 4
0101 5 5
0110 6 6
0111 7 7
1000 8 8
1001 9 9
1010 A 10
1011 B 11
1100 C 12
1101 D 13
1110 E 14
1111 F 15

If we want to 'set' the fourth bit, we AND the value with 8 (1000).  Here we will AND 8 (1000) with 3 (0011) and 6 (0110).

0011 = 3
1000 = 8
----------
1011 = B


0110 = 6
1000 = 8
----------
1110 = E

If we want to 'clear' the fourth bit, we AND the value with 7 (0111).  Here we will AND 7 (0111) with B (1011) and E (1110).

1011 = B
0111 = 7
----------
0011 = 3


1110 = E
0111 = 7
----------
0110 = 6

Nathan.

Wannabe

QuoteIf we want to 'set' the fourth bit, we AND the value with 8 (1000).  Here we will AND 8 (1000) with 3 (0011) and 6 (0110).

0011 = 3
1000 = 8
----------
1011 = B


0110 = 6
1000 = 8
----------
1110 = E

Shouldn't we OR with 8 to get these results...?  :red

Evenbit

Quote from: Wannabe on October 28, 2007, 09:07:59 PM
QuoteIf we want to 'set' the fourth bit, we AND the value with 8 (1000).  Here we will AND 8 (1000) with 3 (0011) and 6 (0110).

0011 = 3
1000 = 8
----------
1011 = B


0110 = 6
1000 = 8
----------
1110 = E

Shouldn't we OR with 8 to get these results...?  :red

And now I know that people are actually paying attention to what I write...   :)

Nathan.