Benjelo Jacob
Benjelo Jacob

Reputation: 17

Binary Representation of Number

I have a 32-bit register in which <7 bit represents address> <1 bit for Read/Write> <24 bits for data> . The data is shifted into and out of the chip MSB first. Logic High(1) for Read and logic low(0) for write. My protocol tells me that I should be using the first 7 bits as address so should that mean it would only refer to first 7 bit for address and the 8th bit is read/write. If I want to read a value 0x200 from the location 0x12 , I should give it as 0x13000200 or 0x25000200.

When I do 0x12000000(address) | 0x01000000(read logic is 1) it will give me 0x13000000. So my doubt is whether it will read from address 0x12 or 0x13 or some other location, since first 7 bits are accessed for address, this logic is ok when address is 0x12 but for 0x13 its bit confusing or should I go with second one " 0x25000200 "0x12 in 7 bit binary is 10010 to this I will add the bit 1 for read so it will become 100101 in turn hexadecimal for this will be 0x25. So I represented the address itself in 7 bits and 8th bit as read so finally it will be like 0x25000200. 0x13 binary is 0001 0011 so how do I represent int this case? How would I read because the 8th bit is already logic 1?

Upvotes: 0

Views: 330

Answers (3)

B Jacob
B Jacob

Reputation: 389

According to your protocol :-

32Bit Register => <7 Bit Address > <1 Bit R/W> <24 Bit Data>

Below are the bit settings to read/write at location 0x12 and 0x13 respectively.

Read (Assuming data is 0 as its a read operation) :-

Read from address 0x12 - 0x25000000 <0010 0101 0000 0000 0000 0000 0000 0000>

Read from address 0x13 - 0x27000000 <0010 0111 0000 0000 0000 0000 0000 0000>

Write (Assuming data is 0x200) :-

Write to address 0x12 - 0x24000200 <0010 0100 0000 0000 0000 0010 0000 0000>

Write to address 0x13 - 0x26000200 <0010 0110 0000 0000 0000 0010 0000 0000>

Upvotes: 1

Santosh A
Santosh A

Reputation: 5351

I think this is wrong : "If I want to write a value 0x200 to the location 0x12 , I can give as 0x12000200". It should have been

0x14000200.

Because: Address 0x12 in binary is "0001-0010", as you are considering only the first 7 bits for address and 1 bit for read/write'(1/0), so the first 8 bits should have been "0010-0011" for read or "0010-0010" for write.

That is address left shift by one position and with read/write bit
(00010010 << 1 & 1/0) which will be 0x15/0x14

Upvotes: 0

iMacTia
iMacTia

Reputation: 671

If the protocol works like you said (first 7 bits for address, then 1 for r/w and remaining 24 for data), then you're correct. See this "explosion" of hex value in binary:

value    address  r/w
0x12   = 0001001   0    You're Writing address 0001001
0x13   = 0001001   1    You're Reading address 0001001

Upvotes: 0

Related Questions