T
T
TheMrViper2015-09-14 19:12:22
go
TheMrViper, 2015-09-14 19:12:22

How does variable and ByteOrder initialization work in golang?

Good day, I would like to get an explanation for this example:
var num int32 = 0x00000020
My machine is running on litle-endian, and with this notation, the number num1 = 5.......... , but the output I get is 32 , and when I look this number is in memory, I see 0x20000000 .
So, why, with such a record of a number, does it reverse the data? It seems that with this initialization of the variable, the data is received in big-endian , and then transferred to the machine order.
I don't have the opportunity to test the code on a big-endian processor, but support for such a processor is needed.
Immediately the second question on the topic, as always reading from the stream, and then when writing to the stream, write the numbers in orderbig-endian regardless of processor order, i.e. if the processor works in big , then write it as it is, and if it works in litle, then convert it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2015-09-15
@gentee

I didn’t quite understand the essence of the question, but the following links may help:
golang.org/pkg/encoding/binary
grokbase.com/t/gg/golang-nuts/129jhmdb3d/go-nuts-h...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question