Jump to content
IGNORED

How to ell what bits a number sets?


Mclaneinc

Recommended Posts

Hi folks, its a Looooooooooooong time since I programmed on the Atari 8 bit in assembler and even then I wasn't that good, I could write disk copiers but I never got in to setting bits or their usage because my maths was AWFUL, I know, odd to want to program in 6502 which is all maths orentated but that's me by nature, a difficult sod :)

 

So could some kind soul show me in as least technical how I can tell what a number would set bit wise....

  • Like 1
Link to comment
Share on other sites

I'll explain a little clearer, someone has found a set of Silica Users Club cassettes and I noticed the instructions suggest you poke 54018 with 52, so I used the scientific calc in windows to see what the address was (D302) but I saw that basically it was to set bit or bits and was to do with the motor control amongst other things so I wanted to see what bits 52 in Hex would set and don't know the maths to work it out.

 

Hope that helps...

Link to comment
Share on other sites

Right, well in the calculator you'd click on "DEC", type 52, and you'll see hex, octal, and binary notations of the same number. In the example above, I clicked on "DEC" for decimal mode and typed 187. In hex this is BB, and you can see next to "BIN" that bits 7,5,4,3,1 and 0 are all set.

Edited by flashjazzcat
  • Like 1
Link to comment
Share on other sites

Just like flashjazzcat, I'd also strongly recommend keeping a scientific calculator open.

 

Perhaps you haven't noticed, but when you type the number, there's a binary section right below the top section (where your number/result is), so you always instantly see the binary representation of whatever number (be it dec/hex) you are typing.

  • Like 2
Link to comment
Share on other sites

Doing it by hand it's easiest to go to hex first. That in itself is easy for numbers under 256. You just tend to remember the multiples of 16 - 144, 160, 176 etc. that correlate to the first digit.

 

Likewise you remember the bitsettings for the 16 hex digits easily too. In general you don't really use binary for more than 8 bits anyway and usually if you do you know the binary value and want to convert to hex which is easy since you just do it in groups of 4.

  • Like 1
Link to comment
Share on other sites

 

Maybe so; it's a bit confusing the way he's saying it though.

 

No maybe about it: POKE 54018,52 turns the motor on. Actually I typed "HEX" at first but then edited it when I realised no Atari BASIC POKE would be documented in hexadecimal. I'm guessing the OP simply confused HEX with BIN (referring not to 52 but the equivalent bits), but since he came here asking for clarification of the basic concepts anyway, that's not unreasonable.

Link to comment
Share on other sites

No maybe about it: POKE 54018,52 turns the motor on. Actually I typed "HEX" at first but then edited it when I realised no Atari BASIC POKE would be documented in hexadecimal. I'm guessing the OP simply confused HEX with BIN (referring not to 52 but the equivalent bits), but since he came here asking for clarification of the basic concepts anyway, that's not unreasonable.

 

Yeah, after thinking about it myself, I figured he probably was confusing HEX and Binary in the statement I quoted.

 

Anyway, just trying to help clarify things; I don't doubt your ability to convert bases.

Link to comment
Share on other sites

Nope, I was trying to say that it was posted as decimal on the instructions as you would expect a BASIC statement to be, I converted the Decimal address so I could look it up in Mapping the Atari or an online place as many just list them in HEX (unlike Mapping the Atari) and as I was quoting a hex address I talked about converting the 52 to hex so it was all on the same theme, I'm well aware in the calculator it does not matter what notation its in as the calc does the conversion. As for confusing Hex and Binary, er no, I'm daft but I know one is ones and zero's and the other is in 0 - F etc.

 

I just never spotted the BIN on the calc for some odd reason or I'd not have bothered people (the windows 7 calc isn't exactly the same as the Win 10 one in looks..) and I'd forgotten because of non use of deliberate bit setting in what little I'd programmed, that binary shows you the bit pattern.

 

As said, it was more me being nosey as to what the poke statement was doing and the only way I could tell was working out what bits the number 52 set..

 

Molehill and mountain now levelled :) I did make a pigs ear out of the explanation and it sort of sounded a bit like I didn't understand :) Trust me, once shown it was clear as day, thanks chaps...

Edited by Mclaneinc
Link to comment
Share on other sites

Doing this from memory, but this BASIC program should convert integers from 0 to 65535. No checks of any kind.

 

10 DIM BIT$(16)

20 PRINT "ENTER DECIMAL NUMBER ";

30 INPUT DEC

40 FOR I=16 TO 1 STEP -1

50 BIT$(I,I)="0"

60 IF INT(DEC/2)<>DEC/2 THEN BIT$(I,I)="1"

70 DEC=INT(DEC/2)

80 NEXT I

90 PRINT

100 PRINT "BINARY NUMBER ";

110 PRINT BIT$

  • Like 1
Link to comment
Share on other sites

I needed to flip a lot of bits for my Shamus maze conversion project and found it MUCH easier to "think hex" as it really boils down to working with 4 bits at a time. If you keep in mind that bits double in value from lower to higher, it gets quite easy wrap your head around that.

 

Lowest bit set = 1

next bit set = 2

third bit set = 4

fourth bit set = 8

 

for any combinations just add up those numbers and remember to switch to letters after 9, so second and fourth bit set is 8+2=A, to flip on the lowest bit just hike the letter up 1, so 1011 is B, etc.

 

There are a couple of BASICs that allow you to use Hex directly (don't know about binary).

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...