BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Programming Trivia Pop Quiz: Make it TRUE!

According to Wikipedia, "Trivia" refers to bits of information, often of little importance.

 

(Questions posted here are very unlikely to show up on a CLAD exam, for that we have these other discussions)

 

I guess we could have an occasional quick pop quiz that should post no problems to the seasoned programmer, but might stump some of the newcomers for a few minutes. So here is the first one:

 

QUESTION: Given the code shown in the image, find four different inputs that will make the output TRUE when the program is executed.

 

SearchingForTheTruth.png

(Any numeric datatype is allowed, that's why the wire is currently a generic black. All primitives are straight from the palettes. No fake modifications or hidden custom code).

Message 1 of 13
(10,327 Views)

Since I was already privy to the discussion that prompted this, I will give a hint.

Spoiler
There is a value for each of the four integer data types (I8, I16, I32, and I64).

GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 13
(10,308 Views)

You said any numeric datatype is allowed, but that's not completely true 🙂

temp.png

Message 3 of 13
(10,270 Views)

@Gregory wrote:

You said any numeric datatype is allowed, but that's not completely true 🙂

temp.png


Broken wires are allowed, but it would be difficult to generate a TRUE (i.e. the required task!) with broken code. 😄

0 Kudos
Message 4 of 13
(10,268 Views)

so i could do it for integers, not for floats, and i am quite confused.

i hope you will give a nice explanation

Spoiler
strange-math.png

seems my twos-complement knowledge has shrunk to a peanut 😉
the absolute value of -128 is not representable in i8,
the normal operation would be to negate all bits and add 1,
but that doesn't seem to happen here.


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 5 of 13
(10,239 Views)

jwcs,

Spoiler
Do the math in hex and it makes a lot more sense.  Take the I8 as an example.  -128 = 0x80.  Invert all bits yields 0x7F.  Add 1 and you are left with 0x80.

GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 13
(10,232 Views)

@crossrulz

Spoiler
thx.. as i said befor .. peanuts 😉 .. i read up on the twos complement now it makes sense and is the "normal" two complements way

If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 7 of 13
(10,229 Views)

Time for another

Capture.png


"Should be" isn't "Is" -Jay
Message 8 of 13
(9,878 Views)

@JÞB wrote:

Time for another

 


 

Spoiler
temp.png
0 Kudos
Message 9 of 13
(9,875 Views)

@JÞB wrote:

Time for another

Capture.png


That's a Rube Goldberg.  I can replace that with one node.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 13
(9,853 Views)