Braille Bytes ⠢⡦⢆⢎⠞⠞⢖⠄⠢⣎⡖⢖⣦

Post your working scripts, libraries and tools.
User avatar
FredOoo
Posts: 186
Joined: 07 May 2019, 21:58
Location: Paris

Braille Bytes ⠢⡦⢆⢎⠞⠞⢖⠄⠢⣎⡖⢖⣦

Post by FredOoo » 30 Aug 2020, 16:45

It's about visualizing bytes, not about blind language.

BBytes( 255 ) -> ∫⣿∫
BBytes( ord("A") ) -> ∫⢂∫
BBytes( ord("本") ) -> ∫⢶⠜∫
BBytes( ord("軔") ) -> ∫⠠⣏⡻∫

Code: Select all

;#! AHK v2.a122 64 Unicode ; UTF-16_LE_BOM

/*
    ∫⣿∫ Braille Bytes (Big-endian)
    -----------------------------------------------------------------------------
      ⠢⡦⢆⢎⠞⠞⢖⠄⠢⣎⡖⢖⣦                                    ◷ 2020-08-26
      Computers store information in various sized groups of binary bits.
      If sometime you feel blind, use Braille Bytes to visualize.
      • Braille Pattern Dots: U+2800 U+28FF
        https://en.wikipedia.org/wiki/Braille_Patterns
      • ON HOLY WARS AND A PLEA FOR PEACE
        Who's on first? Zero or One ?? (Danny Cohen)
        https://www.ietf.org/rfc/ien/ien137.txt
      • ⓕ by FredOoo @ autohotkey.com/boards
      • Examples :

        Horizontal bars become vertical bars
        byte -> 8765 4321  -> 8 4  -> ∫⣿∫    	    1  -> 0000 0001  -> 0 0  -> ∫⢀∫
                              7 3            	                        0 0
                              6 2            	                        0 0
                              5 1            	                        0 1

        129  -> 1000 0001  -> 1 0  -> ∫⢁∫    	  255  -> 1111 1111  -> 1 1  -> ∫⣿∫
                              0 0            	                        1 1
                              0 0            	                        1 1
                              0 1            	                        1 1

        256  -> 0000 0001  0000 0000  -> 0 0  0 0  -> ∫⢀⠀∫
                                         0 0  0 0
                                         0 0  0 0
                                         0 1  0 0

        65535  -> 1111 1111  1111 1111  -> 1 1  1 1  -> ∫⣿⣿∫
                                           1 1  1 1
                                           1 1  1 1
                                           1 1  1 1

        System 32-bit -> ⣿⣿⣿⣿     System 64-Bit -> ⣿⣿⣿⣿⣿⣿⣿⣿

        ASCII -> ⣿                 UTF-16 -> ⣿⣿ or more

        ⣾	⣽	⣻	⢿	⣷	⣯	⣟	⡿	<-  by Filling the missing bit,
        2⁷	2⁶	2⁵	2⁴	2³	2²	2¹	2⁰  <|  you Add this value to the entire byte
		128	64	32	16	8	4	2	1	 |
*/


;; Demo
;;======
¶ := "`n"
; Depending on your font, use full height brackets. (Here is maths integral ∫)
; It might otherwise be difficult to judge the vertical alignment of the dots.
MsgBox "0 -> ∫"     BBytes( 0 )        "∫" ¶ ; -> ∫⠀∫
     . "255 -> ∫"   BBytes( 255 )      "∫" ¶ ; -> ∫⣿∫
     . "65535 -> ∫" BBytes( 65535 )    "∫" ¶ ; -> ∫⣿⣿∫
     . "65536 -> ∫" BBytes( 65536 )    "∫" ¶ ; -> ∫⢀⠀⠀∫
     . "65 -> ∫"    BBytes( 65 )       "∫" ¶ ; -> ∫⢂∫
     . "A -> ∫"     BBytes( ord("A") ) "∫" ¶ ; -> ∫⢂∫
     . "本 -> ∫"    BBytes( ord("本") ) "∫" ¶ ; -> ∫⢶⠜∫
     . "軔 -> ∫"    BBytes( ord("軔") ) "∫" ¶ ; -> ∫⠠⣏⡻∫ ; U+2F9DE from Supplementary Ideographic Plane
     , "Braille Byts"


BBytes( value ){
    static BPD := map(
        ; Base ∫⠿∫
        0   , 0  ,    4   , 16 ,    2   , 32 ,    6   , 48 , ;    ∫⠀⠐⠠⠰∫
        128 , 1  ,    132 , 17 ,    130 , 33 ,    134 , 49 , ;    ∫⠁⠑⠡⠱∫
        64  , 2  ,    68  , 18 ,    66  , 34 ,    70  , 50 , ;    ∫⠂⠒⠢⠲∫
        192 , 3  ,    196 , 19 ,    194 , 35 ,    198 , 51 , ;    ∫⠃⠓⠣⠳∫
        32  , 4  ,    36  , 20 ,    34  , 36 ,    38  , 52 , ;    ∫⠄⠔⠤⠴∫
        160 , 5  ,    164 , 21 ,    162 , 37 ,    166 , 53 , ;    ∫⠅⠕⠥⠵∫
        96  , 6  ,    100 , 22 ,    98  , 38 ,    102 , 54 , ;    ∫⠆⠖⠦⠶∫
        224 , 7  ,    228 , 23 ,    226 , 39 ,    230 , 55 , ;    ∫⠇⠗⠧⠷∫
        8   , 8  ,    12  , 24 ,    10  , 40 ,    14  , 56 , ;    ∫⠈⠘⠨⠸∫
        136 , 9  ,    140 , 25 ,    138 , 41 ,    142 , 57 , ;    ∫⠉⠙⠩⠹∫
        72  , 10 ,    76  , 26 ,    74  , 42 ,    78  , 58 , ;    ∫⠊⠚⠪⠺∫
        200 , 11 ,    204 , 27 ,    202 , 43 ,    206 , 59 , ;    ∫⠋⠛⠫⠻∫
        40  , 12 ,    44  , 28 ,    42  , 44 ,    46  , 60 , ;    ∫⠌⠜⠬⠼∫
        168 , 13 ,    172 , 29 ,    170 , 45 ,    174 , 61 , ;    ∫⠍⠝⠭⠽∫
        104 , 14 ,    108 , 30 ,    106 , 46 ,    110 , 62 , ;    ∫⠎⠞⠮⠾∫
        232 , 15 ,    236 , 31 ,    234 , 47 ,    238 , 63 , ;    ∫⠏⠟⠯⠿∫
    )
    _ord( byte ){
    	; BPD order
    	base  := byte & 238 ; ∫⠿∫
    	block := (byte&16==16) + (byte&1==1)*2  ; 0∫⠀∫  1∫⡀∫  2∫⢀∫  3∫⣀∫
    	return  BPD[ base ] + block*64
    }
    _code( byte ){
        ; BByte U+code
        return 0x2800 + _ord( byte )
    }
    ; BBytes Dots ⣿
	result := ''
    if type(value)="Integer" && value>=0 {
        if !value
            return chr(_code( 0 ))  ; ∫⠀∫
		while value > 0 {
		    result := chr(_code( value & 0x00FF )) result
		    value >>= 8
		}
		return result
	} else
		throw Exception("Error: Must use Positive Integer value")
}
Last edited by FredOoo on 15 Sep 2020, 17:48, edited 5 times in total.
(Alan Turing) « What would be the point of saying that A = B if it was really the same thing? »
(Albert Camus) « Misnaming things is to add to the misfortunes of the world. »


User avatar
FredOoo
Posts: 186
Joined: 07 May 2019, 21:58
Location: Paris

⠢⡦⢆⢎⠞⠞⢖⠄⠢⣎⡖⢖⣦

Post by FredOoo » 15 Sep 2020, 12:03

reserved
(Alan Turing) « What would be the point of saying that A = B if it was really the same thing? »
(Albert Camus) « Misnaming things is to add to the misfortunes of the world. »

effel
Posts: 546
Joined: 16 Jan 2018, 13:34

Re: Braille Bytes ⠢⡦⢆⢎⠞⠞⢖⠄⠢⣎⡖⢖⣦

Post by effel » 15 Sep 2020, 12:25

your reservation lets hope that something will come
⠪⢾⣦⢖⠶⠂⡂⢞⢎⠖⡖⠼⠖⢖
Last edited by effel on 15 Sep 2020, 15:22, edited 1 time in total.

User avatar
FredOoo
Posts: 186
Joined: 07 May 2019, 21:58
Location: Paris

Re: Braille Bytes ⠢⡦⢆⢎⠞⠞⢖⠄⠢⣎⡖⢖⣦

Post by FredOoo » 15 Sep 2020, 14:50

It will come but maybe not so soon. There are still several issues to be resolved.
BBytes are cute and fun but maybe not that useful… I do this to learn AHK.
Hope people will help when I'll say « Feedback is welcome ! »

Image
(Alan Turing) « What would be the point of saying that A = B if it was really the same thing? »
(Albert Camus) « Misnaming things is to add to the misfortunes of the world. »

User avatar
FredOoo
Posts: 186
Joined: 07 May 2019, 21:58
Location: Paris

Re: Braille Bytes ⠢⡦⢆⢎⠞⠞⢖⠄⠢⣎⡖⢖⣦

Post by FredOoo » 10 Jun 2022, 20:40

 
No more BPD := map(…) so v3 is lighter and faster.

You can revers: Bchr_byte( "⢂" ) → 65, witch is "A"
 
This is made to study and visualise encoding and bits…
 

Code: Select all

if a_ScriptFullPath=a_LineFile {
    ; If this script is executed and not included,
    ; this démo will run.
    ¶ := '`n'
    msg := "BB.bytes( 'A' ) → "	BB.bytes( "A" )   	    ¶ ; ∫⢂∫
    msg .= "BB.bytes( '📝' ) → " BB.bytes( "📝" )       ¶ ; ∫⡋⣜∫⡛⣛∫
    msg .= "BB.rev( ord('⢂') ) → "	BB.rev( ord("⢂") )	¶ ; 64
    msg .= "BB.isBB( '⢂' ) → "  BB.isBB( "⢂" )         ¶ ; true
    msg .= "BB.UShort( 65535 ) → "  BB.UShort( 65535 )  ¶ ; ⣿⣿
    msgBox msg, "Démo BBytes", 0x40000
}


class BB { ; Braille Bytes version 3.1

    ;; v2 compatible:

    static ∫   := "∫"
        ; Depending on your font, use full height brackets. (Here is maths integral ∫)
        ; It might otherwise be difficult to judge the vertical alignment of the dots.

    ; ‹byte› : Normal byte ( ord('A') = 65 )
    ; ‹Bo›   : Weird order of Braille dots… ( 130 = 64 in block 2 )
    ; ‹Bchr› : Braille dot character ∫⢂∫ for 'A'
    ; ‹_code›: Code Point

    static _ord( byte ){ ; « A » 65 → 130 : ‹byte› → ‹Bo›
        ;;Historical 6-dot cell  ∫⠿∫                                 byte    B_order
        return 0 | (byte & 128 ?1   :0)  |  (byte & 8   ?8   :0)   ;  7  3    0  3
                 | (byte & 64  ?2   :0)  |  (byte & 4   ?16  :0)   ;  6  2    1  4
                 | (byte & 32  ?4   :0)  |  (byte & 2   ?32  :0)   ;  5  1    2  5
        ;;Blocks  0∫⠀∫  1∫⡀∫  2∫⢀∫  3∫⣀∫
                 | (byte & 16  ?64  :0)  |  (byte & 1   ?128 :0)   ;  4  0    6  7
    }
    static _code( byte ){ ; ‹Bo› → Code Point
        ; BByte code = BPDot Unicode code
        return 0x2800 + this._ord( byte )
    }
    static bytes( value, CP:='ASCII' ){
        ; BByte char = BPDot Unicode char
        ; Returns multi Bchr, but you will get A → ∫⢂∫ not ∫⢂⠀∫ UTF-16
        result := ''
        ;; INTEGER ⩾ 0
        if type(value)="Integer" && value>=0 {
            if !value {
                return chr(this._code( 0 ))  ; ∫⠀∫
            }
            while value > 0 {
                result := chr(this._code( value & 0x00FF )) result
                value >>= 8
            }
            ;a_Clipboard := this.∫ result this.∫
            return result
        ;; STRING
        } else if type(value)="String" {
            if !value
                result .= this.∫ result chr(this._code( 0 ))
            loop strLen(value) {
                result .= this.∫ this.bytes( ord(subStr(value,a_Index,1)) )
            }
            return result this.∫
        ;;
        } else {
            throw ValueError("Error: Must use Positive Integer value, or a String.`nLine: " a_LineNumber)
        }
    }

    ;; New in BB v3:

    static rev( Bo ){ ; 130 → 65 « A » : ‹Bo› → ‹byte›
        ;;Historical 6-dot cell  ∫⠿∫
        return 0 | (Bo & 1   ?128 :0)  |  (Bo & 8   ?8   :0)
                 | (Bo & 2   ?64  :0)  |  (Bo & 16  ?4   :0)
                 | (Bo & 4   ?32  :0)  |  (Bo & 32  ?2   :0)
        ;;Blocks  0∫⠀∫  1∫⡀∫  2∫⢀∫  3∫⣀∫
                 | (Bo & 64  ?16  :0)  |  (Bo & 128 ?1   :0)
    }
    static byte_Bchr( byte ){
        return chr(this._code(byte))
    }
    static Bchr_byte( Bchr ){
        return this.rev( ord(Bchr)-0x2800 )
    }

    static UChar( value ){ ; 8 bits → ∫⢂∫
        return chr(this._code( value ))
        ;
    }
    static UShort( value ){ ; 16 bits → ∫⢂⠀∫
        right := value & 0x00FF
        value >>= 8
        left  := value & 0x00FF
        return chr(this._code( right )) chr(this._code( left ))
    }
    static isBB( cha ){
        o := ord(cha)
        return o>=0x2800 and o<=0x28FF
    }
}
(Alan Turing) « What would be the point of saying that A = B if it was really the same thing? »
(Albert Camus) « Misnaming things is to add to the misfortunes of the world. »

Post Reply

Return to “Scripts and Functions (v2)”