Padded Binary String - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Utilities (https://staging.qb64phoenix.com/forumdisplay.php?fid=8) +---- Thread: Padded Binary String (/showthread.php?tid=810) Pages:
1
2
|
Padded Binary String - James D Jarvis - 08-25-2022 A function to create a padded binary string. if _bin$ would return "10" this can return "00000010" EDIT: corrected a typo in function the demo let slip past but using this in another program exposed the error. All good now. Code: (Select All) 'binpad$ RE: Padded Binary String - mnrvovrfc - 08-25-2022 Code: (Select All) 'this allows a negative value padded by zeroes after sign I needed it even more with hexadecimal numbers. RE: Padded Binary String - James D Jarvis - 08-25-2022 Nice. RE: Padded Binary String - mnrvovrfc - 08-25-2022 I had to write this function because it's near impossible to come up with a near-equivalent to "printf()" from C, because it could take at least two parameters. It became necessary to pad with zeroes at the front of an integer, such as giving serial numbers as filenames and making sure every single filename was the same number of characters. Should have been able to do that "PRINT USING" trick saving to a temporary file only to enter its contents into a string, to pad an integer with zeroes, but not just with asterisks or spaces. :/ RE: Padded Binary String - SMcNeill - 08-25-2022 (08-25-2022, 01:56 AM)mnrvovrfc Wrote: I had to write this function because it's near impossible to come up with a near-equivalent to "printf()" from C, because it could take at least two parameters. It became necessary to pad with zeroes at the front of an integer, such as giving serial numbers as filenames and making sure every single filename was the same number of characters. Sounds like what you wanted to do was something similar to this? Code: (Select All) Dim ss(8) As String RE: Padded Binary String - Pete - 08-25-2022 You're good a padding. How about pubtracting? Oh right, pub-tractoring. Sorry! Pete - Never let a farm pun go to waist. RE: Padded Binary String - SMcNeill - 08-25-2022 (08-25-2022, 04:53 AM)Pete Wrote: You're good a padding. How about pubtracting? I was drunk and once drove my tractor into a pond. That was an attempt at sub-tractoring! RE: Padded Binary String - Pete - 08-25-2022 I hope you remembered to bale before you hit the water! Pete RE: Padded Binary String - RhoSigma - 08-25-2022 Code: (Select All) bn$ = _BIN$(whateverNumber) 'the binary string returned by _BIN$ RE: Padded Binary String - mnrvovrfc - 08-25-2022 Thank you to Steve and RhoSigma for the elegant solutions. |