V
V
Vadim Rublev2020-06-21 06:47:47
go
Vadim Rublev, 2020-06-21 06:47:47

Why is []byte value displayed differently in different cases?

Why is the []byte slice value displayed differently?
var x int = 5
var y string = string(x) //
var z = []byte(y) // [5]

var str string = string([]byte{5}) //
https://play. golang.org/p/m-tGRG91XPa

And there - why is x also unreadable?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
index0h, 2020-06-21
@Vadim Rublev

By converting an int to a string(int) you will not get a string with the value "5" you will get a string with character number 5 in utf8.
For this reason, it is not visible, it is not a printable character www.fileformat.info/info/unicode/char/0005/index.htm
In the case of output as an array of bytes, you will get the original numeric value, but not its character representation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question