Using PORTD

Hello, complete newbie and I'm having a problem solving the following:

"A complete 8-bit PORTD is orientated as output. Arduino digital pins are 0-7.
In order to set 2,5,7,4 to a high level (5V), and all the others to a low level (0), we use the command:

PORTD = x;

x = ?"

Sorry if this is the wrong place to ask or if I translated something poorly as English is not my main language, but would really like some help with this :cry:

I think they are asking "What is the numeric value of an 8-bit number that has bits 2, 4, 5, and 7 set (1) and the other bits clear (0).

Remember that bits are numbered in order with 0 being the rightmost/least significant bit and 7 being the leftmost/most significant bit.

you gave us no information about what you know. we can't know what to tell you until you tell us what you know.

PORTD is a row of pins that can be set high or low. it is one byte of memory. if you write a byte to PORTD you set or clear 8 pins simultaneously. PORTD and other ports gives you a way to control 8 ports at once. PORTD works well for controlling an 8 relay module.

If you write a decimal value of 0 to PORTD, you get

PORT: 7 6 5 4 3 2 1 0
DATA: 0 0 0 0 0 0 0 0

If you write a decimal value of 255 to PORTD, you get

PORT: 7 6 5 4 3 2 1 0
DATA: 1 1 1 1 1 1 1 1

If you write a decimal value of 150 to PORTD, you get

PORT: 7 6 5 4 3 2 1 0
DATA: 1 0 0 1 0 1 1 0

a byte set to 10010110 has a decimal value of ( 2 + 4 + 16 + 128 ) = 150.

In order to set 2,5,7,4 to a high level (5V), and all the others to a low level (0), we use the command:

PORTD = x;

x = ?"

is a very poor way to say

Set PORTD to

PORT: 7 6 5 4 3 2 1 0
DATA: 1 0 1 1 0 1 0 0

which would be expressed in decimal as ( 2 + 4 +16 +32 + 128 ) = 182

so, x = 182

or

just set the value of PORTD with

PORTD == 0b10110100, which is the same value in binary

search term: arduino bit manipulation

Oh I see, thanks for replies and sorry if it was a dumb question (problem solved!)