Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / DWORD to BYTES + plus other small functions

Author
Message
Bored of the Rings
16
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 4th Aug 2021 20:11 Edited at: 4th Aug 2021 22:02
Here's a simple way of converting DWORD to BYTES. You can change the MSB also (Most Significant Bit) using the MSB parameter flag (setting to 1) when calling the MKDWORD function.
The example takes in an RGB DWORD value as input and outputs bytes1-4 and various debug tests to validate the program so that it works as it should. I'll be writing the program equivalents in c+, purebasic and AGK.
I have used my original value2base function instead of the recursion version value2baser previously posted as it's not quite right and haven't yet got round to fixing it.



[update 2 - fixed recursion version of function value2baser -choose whatever function you prefer]

Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
16
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 4th Aug 2021 22:04
1st post updated with 2nd version of the code, whiich sees fixed recursion version of function value2baser added and functioning correctly now.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
16
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 5th Aug 2021 16:12
could put bytes in an array, may do that in later version. All this is for a basic OCR reader, looking at MNST pixel images. If that fails will use Python/c+
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
16
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 9th Aug 2021 21:36 Edited at: 13th Aug 2021 07:13
for array version of Dword2Bytes function, replace with this one and then make a call to the mkdword function like this for example:

Dword2ByteAry(t_magic_number)
magic_number=mkdword(bytes(0),bytes(1),bytes(2),bytes(3),1)

the 1 in the last parameter ensures the MSB byte is used first if needed, or just leave to 0 to use LSB.



rename the functions to suit your prefs.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
16
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 13th Aug 2021 07:21 Edited at: 13th Aug 2021 07:22
update to function Dword2ByteAry(dw)- uses bit shifting. see post above this one.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others

Login to post a reply

Server time is: 2021-10-27 04:43:58
Your offset time is: 2021-10-27 04:43:58