How to draw a circuit diagram to check a 4 bits number is odd or even - draw

Like the title, anyone know how to draw a circuit diagram to check a 4 bits number odd or even ??

You don't really need a circuit for this - bit 0 of the input determines whether the number is odd or even, so you can ignore bits 1 - 3 and just use bit 0 as an odd/even output (it will be 1 for odd, 0 for even). So the circuit, such as it is, would look like this:
INPUT OUTPUT
bit 3 o------------- N/C
bit 2 o------------- N/C
bit 1 o------------- N/C
bit 0 o------------------------------------o odd/even

Related

Predicting Cellular Automata

I am attempting to complete an assignment for an AI course however I cannot understand a question. Unfortunately, I cannot find any information on the internet that clearly explains how to predict the next generation in a CA. I have posted a link to a screenshot of my question below.
Image
Edit:
This is my edited answer;
Edited Answer
In Margolus neighborhoods, the grid is divided into 2x2 blocks. Depending on which step you are in, the division of blocks either starts from the top-left corner or is offset one cell down and one cell to the right. (See Wikipedia on Block cellular automata.) Your instructions say to start from the top-left corner.
So you need to divide up the grid into 2x2 blocks. Then, you check how the patterns in each block match the 15 possible Margolus neighborhood configurations:
For the given grid, you end up with the following. The "neighborhoods" are labeled in yellow highlighted text:
Now you look at the rules you were given: MS, D 0; 14; 11; 5; etc. These numbers after the D tell you, in order, how each configuration should change.
0th number in rule (D 0): Counting from 0, the first number tells you how the 0 (empty) configuration should change. The given number is 0, which means empty 2x2 blocks will not change in the next generation.
1st number in rule (D 0; 14;): The next number tells you how the 1 configuration (one X in upper left corner) should change. That number is 14, which means if we have any 2x2 blocks with the 1 configuration, it should morph into the 14 block. We don't have any 1 configurations, so we go to the next number in the rule.
2nd number in rule (D 0; 14; 11;): The next number tells you how the 2 configuration should change, and that number is 11. We have 2 blocks with the 2 configuration (one X in upper right corner), and the rule tells us we need to convert them to configuration 11 (2x2 block filled with X's except lower left corner).
After evaluating these first 3 rules, you end up with:
Continue for the rest of the numbers in the rule and you will have your answer. As for whether the rule is reversible, see here.

Fast way to evaluate the result of a shift

If I want to see in fast what is the result of a code that does shifting (left/right) I usually write down the binary representation and do the shifting.
But for e.g. shifts of 4 it is actually faster to do it write the hex representation and move the character/digit 1 place to the left/right?
Are there any other tricks for this?
Essentially, shifting 4 bits is removing 1 hex because each hex digit is 4 bits in binary. So shifting 8 bits would be like removing 2 hex, and so on.
If you wanted, you could also do the same type of shift with octal, although instead of 4 bits we would be using 3.
Alternately, if you wish to see the translation in decimal rather than octal or hex, you can view shifting as a way to represent division and multiplication.
With shifting left, you can use x1 << x2 as a form of multiplication by 2^x2.
With shifting right, you can use x1 >> x2 as a form of division by 2^x2. Keep note, this will work for positive numbers, not negative.

Flash As3 random selected Disks plus Chance/luck

My question is how can i add chances to the random selected disks in Actionscript3.0.
SO if the player presses the disks button he/she gets 30% chance to roll disk7 and 40% on disk6. How can i pull this trough.
disks.addEventListener(MouseEvent.MOUSE_DOWN, hitDisk);
function hitDisk(event:MouseEvent):void{
disks.gotoAndStop(Math.ceil(Math.random()*7));
}
Disks[movieclip] > haves 7 keyframes with disks inside of it.
The final frame is the special disk. Every disk haves a instance name.
Disks[movieclip] > (frame1)diskOne, (frame2)diskTwo, (frame3)diskThree.....and so on.
(disks are just like dices but round shaped)
Some help would be nice!!! Thanks!!!
I think you want something like this:
function hitDisk(event:MouseEvent):void{
var rand:int = Math.random() * 100; //gives you a number between 0 and 100
if (rand <= 40) //40% chance
disks.gotoAndStop(7);
} else if (rand > 40 && rand <= 70) { //30% chance
disk.gotoAndStop(6);
} else { //30 % chance
disk.gotoAndStop(5);
}
If you search up ‘random number generators with a bias’ or ‘adding a bias to a random number generator’ (something along these lines) you should find ways to do what you want: to have certain numbers in your random number ‘rolling’ algorithm produce certain numbers more then others.
I’m going to make an assumption here that a disc is like a die, but with seven possible outcomes.
This is one basic method I've used in the past for a similar problem.
You mentioned:
30% chance to roll 7
40% chance to roll 6
I’m going to assume then that 1,2,3,4,5 have an equal chance in the missing 30% chance, so 30% divided by 5 is 6% chance for all the other numbers. So:
30% chance to roll 7
40% chance to roll 6
6% chance to roll 5
6% chance to roll 4
6% chance to roll 3
6% chance to roll 2
6% chance to roll 1
So given these percentages (totaling 100%), you could make an array with 100 spaces and:
fill the first 6 indexes with ‘1’
fill the next 6 indexes with ‘2’
fill the next 6 indexes with ‘3’
fill the next 6 indexes with ‘4’
fill the next 6 indexes with ‘5’
fill the next 40 indexes with ‘6’
fill the next 30 indexes with ‘7’
Then use Math.random() to choose an index at random from this array. Since there are 40 chances out of 100 for ‘6’ to be picked, ‘6’ would come out 40% of the time. And so on with the other numbers.
This can be pretty wasteful to have a large array just for this, but you can improve this with some math (right away I can see that the array can actually be half the size and still contain the desired percentages, just by dividing everything by 2). Or you could take advantage of the fact that numbers 1,2,3,4,5 have an equal outcome and separate it out resulting in an even smaller array (just to calculate the biased outcomes), and so forth.

Need help understanding Conway's Game of Life

I'm trying to write code for Conway's Game of Life to determine the immediate next pattern for a given pattern of cells, but I'm not sure whether I really understand the steps. So for example consider the below toad pattern. The cells marked x are alive and those marked - are dead.
-XXX
XXX-
The above should transpose into the following
--x-
x--x
x--x
-x--
The rules as we know are:
A live cell with less than 2 or more than 3 neighbours dies
A live cell with exactly 2 or 3 neighbours survives
A dead cell with exactly 3 neighbours comes to life.
So, the first cell in the input c[0,0] is - and it has 3 live neigbours (one horizontally,vertically and diagonally each), so it should be alive in the output, but it's not. Can someone please explain?
The middle two rows in your output are the ones that correspond to the two rows in your input. The upper left cell in the input corresponds to the second row extreme left in the output, and as you can see, it's alive.
It is alive in the output. It's right here:
--x-
x--x
x--x
-x--
The x in the first row is above the first row in the first output. The rules of Life assume an unbounded plane. If you want to call the top row of the first output 0, you can, but then the top row of the second output is -1.
Well it is. Your 2-line long input is the middle part of your 4-line output. I think when you look at it now you'll understand everything.
Have you looked at least at wikipedia?

Can someone explain to me why overflow always occurs when the last and second last carry bit are different?

overflow = c,n ⊕ c,n−1
I tried it with all four possible cases
c,n c,n-1
-7+2 1001+0010 0 0
7+2 0111+0010 0 1
-7+(-2) 1001+1110 1 0
7+(-2) 0111+1110 1 1
and it seems to work, but can someone explain or prove why?
When adding two numbers with n bits, the result can have n+1 bits. This means that by using n bits for result we cannot represent all of them.
Now, what is an overflow? If we consider a signed number, it will mean that we can extend the number by adding sign bit (MSB) above MSB, and they will be equal. So, when this does not hold (next bit after MSB is not equal to MSB, something that can be detected before truncating the result to n bits), then we say it's overflow.
As is your example, we say that the overflow occurs when after adding two positive number we obtained a negative one (or two negative that gave positive result).
Also, check this answer by Thomas Pornin, I think he explained it wery well.
It's been so long, I have only a vague understanding of what the notation is saying. I'd assume that 'c' is a carry flag, and 'n' is a negative flag. But then what is 'n-1'?
Anyway, I'm guessing your answer pertains to overflow occurring in either direction: from a negative number wrapping over into a positive, and a positive wrapping over into a negative.