| |

VerySource

 Forgot password?
 Register
Search
View: 2049|Reply: 10

Byte storage order of longword in delphi

[Copy link]

2

Threads

8

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-3-2 11:30:01
| Show all posts |Read mode
var
iSourceNode: Longword;
curSequenceNumber: Array [0..4] of Byte;

copymemory (@ curSequenceNumber, @ iSourceNode, sizeof (iSourceNode));


If iSourceNode = 1, copy the memory, then the buffer curSequenceNumber is
01 00 00 00, instead of 00 00 00 01, why? ?

Do I have to manually swap the high and low bytes when each number is written to the buffer? ?
Reply

Use magic Report

0

Threads

40

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-5-12 17:30:01
| Show all posts
01 00 00 00
Equivalent to curSequenceNumber0] = 1;
It was originally put like this
Reply

Use magic Report

0

Threads

40

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-5-13 12:45:01
| Show all posts
The high address indicates a large number, and the high address is the next byte. This is how it was originally placed. Why should it be exchanged?
Reply

Use magic Report

2

Threads

8

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

 Author| Post time: 2020-5-13 21:45:01
| Show all posts
You may not understand what I mean:

If a longword variable occupies 4 bytes in memory, how is it arranged? Would n’t it be 01 00 00 00? ?

The data written by others in vc is 00 00 00 01, but the one I wrote in delphi is 01 00 00 00, so that the buffer is sent out through the socket, it is not the case at all, and the integer like There are more than one variable in the serial language. Will I have to manually exchange the high and low bits for each one? ?
Reply

Use magic Report

0

Threads

40

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-5-17 12:00:01
| Show all posts
I'm not sure how the VC is arranged. I think it should be the same as DELPH.
Otherwise, is it not a mess to write a dynamic link library, but how can it be versatile.

I think the landlord's concerns should be superfluous.

As long as you don't define the sort order yourself.
Reply

Use magic Report

0

Threads

40

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-5-17 22:15:01
| Show all posts
If iSourceNode = 1, copy memory is equivalent to PLongword (@curSequenceNumber [0]) = iSourceNode;
A similar mechanism is used in the C language, and it should be error-free.
Don't specify which byte writes what value by yourself
Reply

Use magic Report

0

Threads

40

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-5-17 23:00:01
| Show all posts
If iSourceNode = 1, copy memory is equivalent to PLongword (@curSequenceNumber [0]) ^ = iSourceNode;
A similar mechanism is used in the C language, and it should be error-free.
Don't specify which byte writes what value by yourself
Reply

Use magic Report

2

Threads

8

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

 Author| Post time: 2020-5-19 22:00:01
| Show all posts
Then I want to write the value 1 into the 4-byte buffer and get 00 00 00 01, how to do it? ?

var
iSourceNode: Longword;
curSequenceNumber: Array [0..4] of Byte;

iSourceNode: = 1;

....................
What's next? How can we make curSequenceNumber 00 00 00 01 instead of 01 00 00 00? ? ?
Reply

Use magic Report

0

Threads

40

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-5-21 10:45:01
| Show all posts
var
iSourceNode: Longword;
curSequenceNumber: Array [0..4] of Byte;
begin
iSourceNode: = 1;
PLongword (@curSequenceNumber [0]) ^: = iSourceNode shl 32;
...
Reply

Use magic Report

0

Threads

40

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-5-21 11:45:01
| Show all posts
It should be like this: PLongword (@curSequenceNumber [0]) ^: = iSourceNode shl 24;
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list