Hi,
I have a hex value as string and want to write it to a file.
the hex number is F088 for example
this should be $F0 and $88 in the file and take two bytes of space.
(hi and low byte)
writing a hex value to file
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
Re: writing a hex value to file
HEXadecimal values use 2 characters to express one byte of information.
That would require 4 bytes to express it as a HEX$ value, but you could convert each two characters into an ASCII byte value ranging from 0 to 255 for 00 to FF.
So if we have the HEX$ text values we can use VAL with "&H" prefix to get the byte value:
hexa$ = "F0"
byte% = VAL("&H" + hexa$)
We can then PRINT # or PUT # the value into a file as an ASCII character:
ascii$ = CHR$(byte%) '0 to 255 only
PUT #1, , ascii$
If you use QB64 you can put each value into a file AS _UNSIGNED _BYTE.
That would require 4 bytes to express it as a HEX$ value, but you could convert each two characters into an ASCII byte value ranging from 0 to 255 for 00 to FF.
So if we have the HEX$ text values we can use VAL with "&H" prefix to get the byte value:
hexa$ = "F0"
byte% = VAL("&H" + hexa$)
We can then PRINT # or PUT # the value into a file as an ASCII character:
ascii$ = CHR$(byte%) '0 to 255 only
PUT #1, , ascii$
If you use QB64 you can put each value into a file AS _UNSIGNED _BYTE.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0