Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

logical operators in C

Name: Roberto Pastrana 2009-04-24 0:12

Hi /prog/
I need to do this exact thing, but only using logical operators

it prints "OP is a faggot" when one of the numbers is negative and the other is 0 or positive
-----------------------------------------
#include <stdio.h>

int main ()

{
    int a;
    int b;

    puts("Ingrese un valor.\n");
    scanf("%d", a)
    puts("Ingrese otro valor.\n");
    scanf("%d", b)

    if (a<0)
    {
        if (b>=0)
        {
            puts "OP is a faggot"
        }
    } else {
        if (b<0)
        {
            puts "OP is a faggot"   
        }
    }
}
-----------------------------------------

Name: Anonymous 2009-04-26 2:33

if(a < 0 ^ b < 0) puts "OP is a faggot";

Name: Anonymous 2009-04-26 3:17

>>41
In Sepples, the bitwise exact or operator returns an integer, which can be implicitly converted to a boolean, but it is not good form to do so. In fact, you've made 3 implicit conversions. bool to int and bool to int and the resulting int to bool.

EXPERT POOR FORM IN AN EXPERT BAD LANGUAGE

Name: Anonymous 2009-04-26 3:24

>>42
You are, aware booleans in sepples are just ints right? There is no actual conversion taking place anywhere.

Name: Anonymous 2009-04-26 6:10

>>42
You are, aware floats in sepples are just bits right? There is no actual conversion taking place anywhere.

Name: Anonymous 2009-04-26 6:43

>>43,44
You, are, aware, how many fucking, commeas, you, are just, using right? There is no actual fucking point in commas taking place anywhere.

Name: Anonymous 2009-04-26 7:21

>>44
Yes there is. When you convert a float to another type the bits will get changed and shifted around to match the destination format specification, read: converted. No such thing happens for boolean->int or int->boolean, it simply remains as is.

Name: Anonymous 2009-04-26 7:34

>>46
 int i = 42;
0041138E  mov         dword ptr [i],2Ah
 bool f = i;
00411395  cmp         dword ptr [i],0
00411399  setne       al  
0041139C  mov         byte ptr [f],al

The bits of int i (eax) are changed to be either 0 or 1, before being copied to the bool f.
Heck, you could even say the integer is "converted" into a boolean.

Name: Trollbot9000 2009-07-01 8:53

Those that understand binary those who dont!

Name: ​​​​​​​​​​ 2010-10-26 2:38

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List