# Read\_stream\_to\_codes

**URL:** <https://swi-prolog.discourse.group/t/read-stream-to-codes/2000>\
**Category:** Predicate\
**Created:** [March 11, 2020, 11:06pm UTC](https://swi-prolog.discourse.group/t/read-stream-to-codes/2000 "2020-03-11T23:06:25Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [March 12, 2020, 10:07am UTC](https://swi-prolog.discourse.group/t/read-stream-to-codes/2000/6 "2020-03-12T10:07:59Z")

</div>

> [@mcculloch](#):
>
> Do I have to do single byte fetches of each byte?

If you are writing the predicates that access the data at the Prolog level directly then yes. But while it may seem like a real problem at first, after you get a few predicates working that pull a few bytes into a word, double word etc, and then use those predicates you quickly find yourself not writing code with predicates where you are directly using [get\_byte/1](https://www.swi-prolog.org/pldoc/man?predicate=get_byte/1) and start to build up higher and higher levels of code. But still under it all is accessing bytes one at a time.

Related post: [Example parse of binary data using DCG](https://swi-prolog.discourse.group/t/example-parse-of-binary-data-using-dcg/1370)

> [@mcculloch](#):
>
> I especially don’t understand how you get a two byte value from one byte, but that’s just me.

If you change the terminology of that sentence it will make more sense. The raw data stored on a file for any encoded data is stored and accesses as raw bytes, when the data is read it is read as one or more groups of bytes then passed through a decoder that converts the bytes into a value. Now the value may itself represent something but in textual display it will most likely be a glyph that is represented as a bit pattern for display on a display device, or the value could be converted to some variation of vector graphics and that is used to create a glyph.

Recently I spent time with UTF-8 which encodes Unicode into bytes for storage with the smallest storage unit being 8 bits or one byte. There is also UTF-16 that encodes Unicode into bytes for storage with the smallest storage unit being 16 bits or two bytes. See: Unicode encoding [UTF-8](https://en.wikipedia.org/wiki/UTF-8) for more details.

> [@mcculloch](#):
>
> 6502 executable

I use to program in 6502 assembly, it was hard having very few general purpose resisters.

---

_[View the full topic](https://swi-prolog.discourse.group/t/read-stream-to-codes/2000)._
