How to resolve the algorithm Literals/Integer step by step in the Verbexx programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Literals/Integer step by step in the Verbexx programming language

Table of Contents

Problem Statement

Some programming languages have ways of expressing integer literals in bases other than the normal base ten.

Show how integer literals can be expressed in as many bases as your language allows.

Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or interpreter as an integer written to a given base. Also show any other ways of expressing literals, e.g. for different types of integers.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Literals/Integer step by step in the Verbexx programming language

Source code in the verbexx programming language

//    Integer Literals: 
//
//    If present, base prefix must be:    0b 0B (binary) 0o 0O (octal) 
//                                        0x 0X (hex)
//
//    If present, length suffix must be:  i I i64 I64 (INT64_T)
//                                        u U u64 U64 (UINT64_T)
//                                        i32 I32 (INT32_T) u32 U32 (UINT32_T)
//                                        i16 I16 (INT16_T) u16 U16 (UINT16_T)
//                                        i8  I8  (INT8_T)  u8  U8  (UINT8_T)
//                                        u1  U1  (BOOL_T)  u0  U0  (UNIT_T) 
//                                        iV  iv  Iv IV             (INTV_T)     

//     Binary       Octal         Decimal       Hexadecimal
//     ------------ ----------    ------------  --------------
@SAY  0b1101        0o016         19999999      0xFfBBcC0088   ; // INT64_T 
@SAY  0B0101        0O777        -12345678      0X0a2B4c6D8eA  ; // INT64_T 
@SAY  0b1101I64     0o707I64      12345678i64   0xFfBBcC00i64  ; // INT64_T 
@SAY  0b1101I       0o57707i     -2345678I      0xfafbbCc99i   ; // INT64_T 
@SAY  0b1001U64     0o555u64      33345678u64   0xFfaBcC00U64  ; // UINT64_T 
@SAY  0b10010100U   0o1234567u    3338u         0x99faBcC0EU   ; // UINT64_T 
@SAY  0B0101i32     0O753I32      987654i32     0XAAb4cCeeI32  ; // INT32_T  
@SAY  0B0101u32     0O573u32      987654U32     0X0BAb4cCeeU32 ; // UINT32_T 
@SAY  0B0101i16     0O753i16     -017654I16     0X000cCffi16   ; // INT16_T  
@SAY  0B0101u16     0O633U16      27654U16      0X000dDbBu16   ; // UINT16_T   
@SAY  0B0101i8      0O153i8      -000114I8      0X000ffi8      ; // INT8_T  
@SAY  0B0101u8      0O132U8       00094U8       0X0000bu8      ; // UINT8_T  
@SAY  0b0u1         0o0u1         00u1 0U1      0x000u1        ; // BOOL_T (FALSE)
@SAY  0B001u1       0O1u1         1u1 01U1      0X1u1 0x001U1  ; // BOOL_T (TRUE ) 
@SAY  0b0u0         0o000u0       00u0 0U0      0x0u0 0X000U0  ; // UNIT_T 
@SAY                             -1234iV                       ; // INTV_T (cpp_int) 
@SAY                              56781234Iv                   ; // INTV_T (cpp_int) 

//  note: _ (underscores) can appear in the main numeric part of the literal, 
//        after any base prefix, and before any length suffix.  If there is
//        no prefix, the numeric literal cannot begin with underscore: 

@SAY 100_000  1_u1  0x_FFFF_u16  1__0__  0x__7890_ABCD_EFAB_CDEF__u64;

  

You may also check:How to resolve the algorithm Case-sensitivity of identifiers step by step in the Ursa programming language
You may also check:How to resolve the algorithm Sorting algorithms/Permutation sort step by step in the C# programming language
You may also check:How to resolve the algorithm Perfect numbers step by step in the Oz programming language
You may also check:How to resolve the algorithm Loops/For step by step in the Prolog programming language
You may also check:How to resolve the algorithm Guess the number/With feedback step by step in the NetRexx programming language