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
???
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
A tutorial on binary numbers
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
Bits From Bytes - the best RepRap kit out there now featuring RepRap V3 with full electronics redesign based on PIC32MX440F256H (English)
MySQL Blog (Serbian)
Elco Blog (Serbian)
Use forum to ask questions, do not use PP
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
Bits From Bytes - the best RepRap kit out there now featuring RepRap V3 with full electronics redesign based on PIC32MX440F256H (English)
MySQL Blog (Serbian)
Elco Blog (Serbian)
Use forum to ask questions, do not use PP
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 by Pommie; 20th May 2008 at 02:00 PM.
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
Bits From Bytes - the best RepRap kit out there now featuring RepRap V3 with full electronics redesign based on PIC32MX440F256H (English)
MySQL Blog (Serbian)
Elco Blog (Serbian)
Use forum to ask questions, do not use PP
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.
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.!
Eric " Good enough is Perfect "
I will NOT answer PM's requesting technical help, please use the Forum
PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/
Link to my Articles: http://www.electro-tech-online.com/a...icgibbs-55450/
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)
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 valueCode: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 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 by arhi; 20th May 2008 at 02:52 PM. Reason: typo
Bits From Bytes - the best RepRap kit out there now featuring RepRap V3 with full electronics redesign based on PIC32MX440F256H (English)
MySQL Blog (Serbian)
Elco Blog (Serbian)
Use forum to ask questions, do not use PP
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.?
Eric " Good enough is Perfect "
I will NOT answer PM's requesting technical help, please use the Forum
PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/
Link to my Articles: http://www.electro-tech-online.com/a...icgibbs-55450/
to be honest, no
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
then if BX = 0xFF00;Code:| BX | | BH | BL |
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
Bits From Bytes - the best RepRap kit out there now featuring RepRap V3 with full electronics redesign based on PIC32MX440F256H (English)
MySQL Blog (Serbian)
Elco Blog (Serbian)
Use forum to ask questions, do not use PP
Last edited by ericgibbs; 20th May 2008 at 04:37 PM.
Eric " Good enough is Perfect "
I will NOT answer PM's requesting technical help, please use the Forum
PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/
Link to my Articles: http://www.electro-tech-online.com/a...icgibbs-55450/
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
??
NO!!
You are going to convert a decimal number into BINARY, NOT BCD!
Where did this idea of adding six come from?? WRONG!!
Your process is correct, apart from adding this silly six.
Eric Gibbs showed the correct solution several posts ago.
JimB
Experience is directly proportional to the value of the equipment ruined.
i transformed it into BCD thats why i added six
is it ok regarding the 24bit register ??
How does adding six transform it into BCD?
JImB
Experience is directly proportional to the value of the equipment ruined.