[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: hard to understand code for the representation of tab
From: |
Patrice Dumas |
Subject: |
Re: hard to understand code for the representation of tab |
Date: |
Sun, 13 Oct 2024 12:57:48 +0200 |
On Sat, Oct 12, 2024 at 08:51:08PM +0100, Gavin Smith wrote:
> Here's an attempt at explaining it:
>
> pl_chars is the current column. We want to find the next multiple of 8
> after the current column, assuming a tab is 8 spaces. We add 8 to the
> current column, and then subtract the remainder when this result is
> divided by 8.
>
> For example
>
> A. 21 + 8 = 28,
> B. Then 28 mod 8 = 4
> C. 28 - 4 = 24.
> D. Finally, we take away the starting point: 24 - 21 = 3.
>
> So we output 3 spaces to get up to 24 columns.
>
> (n & 0xf8) is supposed to do steps B and C combined
> as the binary representation of 0xf8 is 1111 1000 so the result has
> to be a multiple of 8.
>
> However, this doesn't work if there are more than 255 columns (which is
> unlikely, though).
Thanks!
I added a comment based on your explanation.
--
Pat