Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

i am looking for reading material to solve this question..

Status
Not open for further replies.
show the bit configuration of a 24bit register which its contents represents
the decimal number of 295 in binary code??????????

i dont know where to start this thing

what stuff should i read in order to know how to solve this stuff
???
 
Here is the 3 different links telling you about binary system and representation of numbers in binary and other numeral systems.

Representation of numbers
Binary numeral system - Wikipedia, the free encyclopedia
**broken link removed**

you can get some basics about numeral systems here:
Numeral system - Wikipedia, the free encyclopedia

as for your question ... 24bit register contain, well, 24 binary digits, so all you need to do is convert 295(10) in to x(2) so it is:

000000000000000100100111

hope that helps
 
ah, now, depending on the CPU that holds the data, you have 2 groups, big endian (motorolla for e.g.) and little endian (intel for e.g.)... for little endian the representation is "normal" so the number will be arranged in memory as follows:

Base Address+0 Byte0
Base Address+1 Byte1
Base Address+2 Byte2
Base Address+3 Byte3

for big endian it is bit different:
Base Address+0 Byte3
Base Address+1 Byte2
Base Address+2 Byte1
Base Address+3 Byte0

so in your case with 24bit register (3 bytes) it would be
Base Address+0 Byte2
Base Address+1 Byte1
Base Address+2 Byte0

so for big endian cpu the solution to your question is
001001110000000100000000
 
ah, now, depending on the CPU that holds the data, you have 2 groups, big endian (motorolla for e.g.) and little endian (intel for e.g.)... for little endian the representation is "normal" so the number will be arranged in memory as follows:

Base Address+0 Byte0
Base Address+1 Byte1
Base Address+2 Byte2
Base Address+3 Byte3

for big endian it is bit different:
Base Address+0 Byte3
Base Address+1 Byte2
Base Address+2 Byte1
Base Address+3 Byte0

so in your case with 24bit register (3 bytes) it would be
Base Address+0 Byte2
Base Address+1 Byte1
Base Address+2 Byte0

so for big endian cpu the solution to your question is
001001110000000100000000

That is one way to confuse people. Representing numbers in binary has nothing to do with endian. Numbers in any base have the most significant digit first. Your above example is in base 256 and even in that base we put the most significant digit first. How it is stored in memory is a completely different thing.

Edit, to the OP, the answer given above is wrong. The correct answer is 100100111. The (digit) columns are numbered 256,128,64,32,16,8,4,2,1 and if you add up the columns with a one then you will get 295.

Mike.
 
Last edited:
Mike, I might be wrong here as it was reeeeeeaaaaaaly long time ago since I did some ASM programming but if I remember correctly, big endian CPU's store data in registers the same way they store them in RAM .. as the question was show the bit configuration of a 24bit register if I recollect correctly (and please correct me if I'm wrong as I'm not 100% sure) the big endian CPU will have register storing number 295(10) as
Code:
bit23               bit0
|                      |
v                      v                  
001001110000000100000000
 
When we write down the value of a (24bit) register we can do it in any base that we like. Whichever base we choose, we put the most significant digit first. What you are saying is that on a little/big endian computer that pi would be 1.3149562 when we all know it's 3.1415926. The reason I put little/big is because the endianess is simply an argument over which way around the bytes should be stored. Everyone writes 0x123456 to represent a 24 bit number. Nobody switches it around to 0x563412 because of endianess.

Mike.
 
show the bit configuration of a 24bit register which its contents represents
the decimal number of 295 in binary code??????????

i dont know where to start this thing

what stuff should i read in order to know how to solve this stuff
???

hi,
I agree with Mike's solution.

To show the working of how to convert that 295 decimal number.
Subtract the largest 2^n power from the number
so:
295 - 256 = 39..............1
39 cant subtract 128......0
39 cant subtract 64.... .0
39 - 32 = 7..................1
7 cant subtract 16........0
7 cant subtract 8..........0
7 - 4 = 3.....................1
3 - 2 = 1.....................1
1 - 1 = 0.....................1..........lsb

The correct answer is 1,0010,0111
To normalise for a 24 bit pattern, add leading zero's

0000,0000,0000,0001,0010,0111[lsb] the comma's are for clarity only.!
 
When we write down the value of a (24bit) register we can do it in any base that we like. Whichever base we choose, we put the most significant digit first. What you are saying is that on a little/big endian computer that pi would be 1.3149562 when we all know it's 3.1415926. The reason I put little/big is because the endianess is simply an argument over which way around the bytes should be stored. Everyone writes 0x123456 to represent a 24 bit number. Nobody switches it around to 0x563412 because of endianess.

Mike.

Mike, I believe you managed to confuse me, but I want to get this clear in my mind so I will try to explain what I think and allow myself to learn from the master.

I agree that value of any number has nothing to do with endian, nor with cpu itself ... 0x0f0f(16) is same value however the endian philosophy of the CPU is, but, (now this is the part where I believe I'm making a mistake and you please be so kind to make it right) if we do following (now, I have to use C as my ASM is non existing attm)

Code:
unsigned int32 *x[1]; //32 bit int
unsigned int8 *y; //8 bit int

x[0]=0x01020304;
y = x;

// for little endian
if (y[0] == 0x01) { this is true }
if (y[1] == 0x02) { this is true }
if (y[2] == 0x03) { this is true }
if (y[3] == 0x04) { this is true }

//for big endian
if (y[0] == 0x04) { this is true }
if (y[1] == 0x03) { this is true }
if (y[2] == 0x02) { this is true }
if (y[3] == 0x01) { this is true }
now, I believe we can agree with this code ? the value of x is always 0x01020304 but it is stored in RAM differently in big endian then in little endian cpu. same thing should be with the register. Register itself is hold same value on both CPU's but the bit configuration of the register on one and the other CPU is not same. On little endian CPU the bit0 (the rightmost one) have LSB of the value and on big endian CPU that is not the case. As question was how the value affect bit configuration of the register, I assume question is, what is the value of every particular bit in the register and not what is the binary representation of the decimal number, 295 = 0b0100100111 = 0x127, the question was (if I understood it correctly) what would be the actual bit's in the register that will store this value

now, I might be off here, but I'm pretty sure I'm right as I remember I had load of problems when I switched from 8051 to HC... ages ago
 
Last edited:
hi,
Its just the Byte order thats different, not the byte bit pattern/weighting order.

HB,LB...............LB,HB

The bit weighting is always leftmost = highest weighting,, rightmost = lowest.

Does this help.?
 
hi,
Its just the Byte order thats different, not the byte bit pattern/weighting order.

HB,LB...............LB,HB

The bit weighting is always leftmost = highest weighting,, rightmost = lowest.

Does this help.?

to be honest, no :confused:

the bit weight is clear ... binary number is binary number it has nothing to do with byte order. - this part I do not have problem with, from the start. What I am talking about, and that confuses me now (and never before this conversation :) ) is "hardware presentation" ...

if you look at the code I wrote .. (it should be correct) .. you can see that for same value, different endian will store in ram same value with different byte order. Can we agree on that?

Now, let us look at the register, it is also "memory location" only within CPU. and the number is stored in that register (24bit register is 3 bytes) in same order as it is stored in RAM. so, physical location of the highest significant bit of the 3byte binary value will not be on the leftmost physical position of the register that is 3byte big on the big endian box. so, in theory, if we have 2byte register that can be also addressed as 2 single byte registers

Code:
|   BX    |
| BH | BL |

then if BX = 0xFF00;
on low endian
BH=0xff;
BL=0x00;

and on big endian
BH=0x00
BL=0xFF

so the difference is how the value (value is always same) stored physically inside the register/RAM it does not mean that binary representation of that number is different ... as 0x010101 is allways 0x010101 no matter what CPU/MCU/device is used ..

now, where do I make mistake ...

for little endian, if AX = 0xFF00
 
to
if you look at the code I wrote .. (it should be correct) .. you can see that for same value, different endian will store in ram same value with different byte order. Can we agree on that?
I agree its stored in 4 different 8 bit registers, one set in ascending the other in descending byte order.

Now, let us look at the register, it is also "memory location" only within CPU. and the number is stored in that register (24bit register is 3 bytes)
Its not a 24bit register, but three separate, 8 bit registers.

in same order as it is stored in RAM. so, physical location of the highest significant bit of the 3byte binary value will not be on the leftmost physical position of the register that is 3byte big on the big endian box. so, in theory, if we have 2byte register that can be also addressed as 2 single byte registers

Code:
|   BX    |
| BH | BL |

then if BX = 0xFF00;
on low endian
BH=0xff;
BL=0x00;

and on big endian
BH=0x00
BL=0xFF

so the difference is how the value (value is always same) stored physically inside the register/RAM it does not mean that binary representation of that number is different ... as 0x010101 is allways 0x010101 no matter what CPU/MCU/device is used ..

now, where do I make mistake ...

for little endian, if AX = 0xFF00

Hi arhi,
I think the misunderstanding could lie in the fact, that the cpu 'accumulator' is 8 bits wide and the processing is on 8 bit bytes.
Its just the order which the 'acc' accesses the 8 bit bytes, hi thru lo or vice versa.
So the bit weighting is always the same.:)
 
Last edited:
if i understand you correctly..

the register of 24bit
says only that we need to represent it using number of length of 24 digits

so what you did is just transform it into a binary numbers with length 24
and the value of 295

know if i understand you correctly in order to represent 295
into BCD i need to add six 295+6=301
which is
301-256=45 1
45-128 0
45-64 0
45-32 1
13-16 0
13-8 1
5-4 1
1-2 0
1-1 1

which is
000000000000000100101101

am i correct
??
 
know if i understand you correctly in order to represent 295
into BCD
NO!!
You are going to convert a decimal number into BINARY, NOT BCD!


i need to add six 295+6=301
Where did this idea of adding six come from?? WRONG!!

which is
301-256=45 1
45-128 0
45-64 0
45-32 1
13-16 0
13-8 1
5-4 1
1-2 0
1-1 1

which is
000000000000000100101101

am i correct
??
Your process is correct, apart from adding this silly six.
Eric Gibbs showed the correct solution several posts ago.

JimB
 
How does adding six transform it into BCD?

JImB
 
Hi arhi,
I think the misunderstanding could lie in the fact, that the cpu 'accumulator' is 8 bits wide and the processing is on 8 bit bytes.
Its just the order which the 'acc' accesses the 8 bit bytes, hi thru lo or vice versa.
So the bit weighting is always the same.:)

might be the cause of my misunderstanding .. basically when I do sysdev I have to worry about how numbers are stored in RAM if I access memory locations directly (like in my example) .. that is the "core" problem of the whole discussion, as I consider "register" a multibyte memory location...
 
ok...

this is 259 (dec) = 0010 0101 1001 (bcd)

so in order to put it in 24bit register i need to :
000000000000001001011001

am i correct??
 
this is 259 (dec) = 0010 0101 1001 (bcd)

so in order to put it in 24bit register i need to :
000000000000001001011001

am i correct??

Your first question was to show it as binary .. BCD is binary coded decimal that is not same so double check if you need number with base 2, or bcd coded number, with BCD you need to know do you want packed or not BCD code, your answer is true if you want packed BCD (the most common BCD variant).

note that if you do packed BCD addition, you add the numbers as they were binary numbers (perform normal binary addition) and then add 6 to each digit that is larger then 9
 
Hi arhi,
I think the misunderstanding could lie in the fact, that the cpu 'accumulator' is 8 bits wide and the processing is on 8 bit bytes.
Its just the order which the 'acc' accesses the 8 bit bytes, hi thru lo or vice versa.
So the bit weighting is always the same.:)

Endianness - Wikipedia, the free encyclopedia

that's the answer to my problem :) (where is that banging head smiley) ..
for some strange reason, I decided to believe that multibyte value is stored in register the same way as it is stored in memory .. hence all the ping pong ... but now i understand it is not :)

thanks for clarification and sorry for the stubbornest, I had to get to the bottom of it to be able to sleep :D
 
Status
Not open for further replies.

Latest threads

Back
Top