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
|
RE: Padded Binary String - bplus - 08-25-2022 I don't like those negative numbers! Code: (Select All) Do RE: Padded Binary String - bplus - 08-25-2022 (08-25-2022, 04:17 PM)bplus Wrote: I don't like those negative numbers! And we haven't even gotten Real yet! like 3 and 1/3 ;-)) RE: Padded Binary String - SMcNeill - 08-25-2022 Try: Print "Back to decimal? "; Val("&B" + bn$ +"&&") RE: Padded Binary String - RhoSigma - 08-25-2022 (08-25-2022, 04:17 PM)bplus Wrote: I don't like those negative numbers! _BIN$ operates equally to HEX$ and OCT$ with negatives or real numbers. If fact, when I've implemented _BIN$, I just copied the OCT$ stuff and changed that couple lines performing octal base operations into binary operations and plugged that back in as _BIN$, so don't blame me (_BIN$), blame OCT$ instead RE: Padded Binary String - SMcNeill - 08-25-2022 (08-25-2022, 04:21 PM)bplus Wrote:(08-25-2022, 04:17 PM)bplus Wrote: I don't like those negative numbers! Makes perfect sense, if you just think about it for a moment. Some questions can have more than a single answer. After all, let me ask: What is the square root of four?? If you say 2, you're correct! If you say -2, you're also correct! In this case, that's more-or-less what you're seeing here -- the correct answer, but you're only showing HALF the correct answer! Code: (Select All) Dim x As Long You have to specify which variable type you're returning a binary value back to. Is it a byte? integer? long? signed or unsigned? Quick, tell me: What's the value of: 11111111?? Well, you got that wrong! It's 11,111,111!! I never mentioned it was binary, now did I? Of course, it could also be hexadecimal... Which you still got wrong as you didn't think of that possibility either! Or octal... You have to define what those 1's and 0's correspond back to, otherwise the computer just has to make a guess for you. In the case of VAL, it's guessing FLOAT -- not even an integer type at all LOL! -- and gives you the unsigned value back. If you want a signed value, make certain you assign the result to a signed variable. Else, expect the wrong answer. RE: Padded Binary String - bplus - 08-25-2022 "You have to specify which variable type you're returning a binary value back to. Is it a byte? integer? long? signed or unsigned?" I did specify, " Print "Back to decimal?" ";-)) Don't worry about this, I know this will be as fruit fall as getting a Circle fill or reversing Basic's backward ways with the Y axis. It is what it is. RE: Padded Binary String - SMcNeill - 08-25-2022 You got it "back to decimal". You just got it back as an unsigned value rather than a signed one. It's the exact same as saying: (-2) ^ 2 = 4, but SQR(4) doesn't give me (-2)!! |