Bitwise operators
Bit level operations on integers.
Every program can use these operators. No import is necessary.
| Operator | Arguments | Gives |
|---|---|---|
bit_and |
left: int, right: int | int |
bit_not |
value: int | int |
bit_or |
left: int, right: int | int |
bit_xor |
left: int, right: int | int |
Target support marks
- Own template
- Default template
- No template
The operator works for a target with an own template and for a target with the default template. The default template is the * entry of the definition: it writes the same code for every target that has no template of its own. A target with no template writes no code, and a program that uses the operator does not compile for that target.
bit_and
(bit_and left right) → int
bit_and(left: int, right: int)Gives the bitwise AND of the two integers.
A bit of the result is 1 when the same bit is 1 in both arguments.
Target support
- JavaScript: own template
- TypeScript: own template
- Go: own template
- Rust: own template
- Python: own template
- Java: own template
- Kotlin: own template
- Dart: default template
- Swift: own template
- C#: own template
- C++: own template
- PHP: default template
- Scala: default template
Bit operations on an integer
class Main { sfn main:void () { def flags 12 def mask 10 print ("and " + (bit_and flags mask)) print ("or " + (bit_or flags mask)) print ("xor " + (bit_xor flags mask)) print ("not " + (bit_not flags)) }}const flags = 12;const mask = 10;console.log("and " + (flags & mask));console.log("or " + (flags | mask));console.log("xor " + (flags ^ mask));console.log("not " + (~flags));The complete file
class Main { constructor() { }}/* static JavaSript main routine at the end of the JS file */function __js_main() { const flags = 12; const mask = 10; console.log("and " + (flags & mask)); console.log("or " + (flags | mask)); console.log("xor " + (flags ^ mask)); console.log("not " + (~flags));}__js_main();const flags : number = 12;const mask : number = 10;console.log("and " + (flags & mask));console.log("or " + (flags | mask));console.log("xor " + (flags ^ mask));console.log("not " + (~flags));The complete file
export class Main { constructor() { }}/* static JavaSript main routine at the end of the JS file */function __js_main() { const flags : number = 12; const mask : number = 10; console.log("and " + (flags & mask)); console.log("or " + (flags | mask)); console.log("xor " + (flags ^ mask)); console.log("not " + (~flags));}__js_main();var flags int64= int64(12);var mask int64= int64(10);fmt.Println( strings.Join([]string{ "and ",strconv.FormatInt(int64(flags & mask), 10) }, "") )fmt.Println( strings.Join([]string{ "or ",strconv.FormatInt(int64(flags | mask), 10) }, "") )fmt.Println( strings.Join([]string{ "xor ",strconv.FormatInt(int64(flags ^ mask), 10) }, "") )fmt.Println( strings.Join([]string{ "not ",strconv.FormatInt(int64(^flags), 10) }, "") )The complete file
package mainimport ( "strings" "strconv" "fmt")type Main struct {}
func CreateNew_Main() *Main { me := new(Main) return me;}func main() { var flags int64= int64(12); var mask int64= int64(10); fmt.Println( strings.Join([]string{ "and ",strconv.FormatInt(int64(flags & mask), 10) }, "") ) fmt.Println( strings.Join([]string{ "or ",strconv.FormatInt(int64(flags | mask), 10) }, "") ) fmt.Println( strings.Join([]string{ "xor ",strconv.FormatInt(int64(flags ^ mask), 10) }, "") ) fmt.Println( strings.Join([]string{ "not ",strconv.FormatInt(int64(^flags), 10) }, "") )}let __rg_main_thread = std::thread::Builder::new().stack_size(512 * 1024 * 1024) .spawn(__rg_main_body).expect("could not start the main thread");__rg_main_thread.join().expect("main thread panicked");The complete file
#![allow(dead_code)]
#[derive(Clone)]struct Main {}impl Main { pub fn new() -> Self { Self { } }}fn main() { let __rg_main_thread = std::thread::Builder::new().stack_size(512 * 1024 * 1024) .spawn(__rg_main_body).expect("could not start the main thread"); __rg_main_thread.join().expect("main thread panicked");}fn __rg_main_body() { let flags: i64 = 12; let mask: i64 = 10; println!("and {}", flags & mask); println!("or {}", flags | mask); println!("xor {}", flags ^ mask); println!("not {}", (!flags));}flags = 12mask = 10print("and " + str(((flags) & (mask))))print("or " + str(((flags) | (mask))))print("xor " + str(((flags) ^ (mask))))print("not " + str((~flags)))The complete file
# -*- coding: utf-8 -*-from __future__ import annotationsfrom typing import Optional
class Main: def __init__(self) -> None: pass# Main entry pointdef main(): flags = 12 mask = 10 print("and " + str(((flags) & (mask)))) print("or " + str(((flags) | (mask)))) print("xor " + str(((flags) ^ (mask)))) print("not " + str((~flags)))if __name__ == "__main__": main()RgArgs.args = args;final Integer flags = 12;final Integer mask = 10;System.out.println(String.valueOf( "and " + ((flags) & (mask)) ) );System.out.println(String.valueOf( "or " + ((flags) | (mask)) ) );System.out.println(String.valueOf( "xor " + ((flags) ^ (mask)) ) );System.out.println(String.valueOf( "not " + (~flags) ) );The complete file
import java.io.*;
public class Main {
public static void main(String [] args ) { RgArgs.args = args; final Integer flags = 12; final Integer mask = 10; System.out.println(String.valueOf( "and " + ((flags) & (mask)) ) ); System.out.println(String.valueOf( "or " + ((flags) | (mask)) ) ); System.out.println(String.valueOf( "xor " + ((flags) ^ (mask)) ) ); System.out.println(String.valueOf( "not " + (~flags) ) ); }}
public class RgArgs { public static String[] args = new String[0];}__g_args = argsval flags : Int = 12;val mask : Int = 10;println( "and " + (((flags) and (mask))).toString() )println( "or " + (((flags) or (mask))).toString() )println( "xor " + (((flags) xor (mask))).toString() )println( "not " + (((flags).inv())).toString() )The complete file
class Main {
}
var __g_args : Array<String> = arrayOf()
fun main(args : Array<String>) { __g_args = args val flags : Int = 12; val mask : Int = 10; println( "and " + (((flags) and (mask))).toString() ) println( "or " + (((flags) or (mask))).toString() ) println( "xor " + (((flags) xor (mask))).toString() ) println( "not " + (((flags).inv())).toString() )}__g_args = args;int flags = 12;int mask = 10;print( "and " + (((flags) & (mask))).toString() );print( "or " + (((flags) | (mask))).toString() );print( "xor " + (((flags) ^ (mask))).toString() );print( "not " + ((~flags)).toString() );The complete file
class Main {}
List<String> __g_args = <String>[];
void main(List<String> args) { __g_args = args; int flags = 12; int mask = 10; print( "and " + (((flags) & (mask))).toString() ); print( "or " + (((flags) | (mask))).toString() ); print( "xor " + (((flags) ^ (mask))).toString() ); print( "not " + ((~flags)).toString() );}let flags : Int = 12let mask : Int = 10print("and " + String(((flags) & (mask))))print("or " + String(((flags) | (mask))))print("xor " + String(((flags) ^ (mask))))print("not " + String((~(flags))))The complete file
func ==(l: Main, r: Main) -> Bool { return l === r}final class Main : Hashable { func hash(into hasher: inout Hasher) { hasher.combine(ObjectIdentifier(self)) }}// Main entry pointfunc __main__swift() { let flags : Int = 12 let mask : Int = 10 print("and " + String(((flags) & (mask)))) print("or " + String(((flags) | (mask)))) print("xor " + String(((flags) ^ (mask)))) print("not " + String((~(flags))))}__main__swift()int flags = 12;int mask = 10;Console.WriteLine("and " + ((flags) & (mask)));Console.WriteLine("or " + ((flags) | (mask)));Console.WriteLine("xor " + ((flags) ^ (mask)));Console.WriteLine("not " + (~flags));The complete file
using System;class Main { static void Main( string [] args ) { int flags = 12; int mask = 10; Console.WriteLine("and " + ((flags) & (mask))); Console.WriteLine("or " + ((flags) | (mask))); Console.WriteLine("xor " + ((flags) ^ (mask))); Console.WriteLine("not " + (~flags)); }}int flags = 12;int mask = 10;std::cout << std::string("and ") + std::to_string(((flags) & (mask))) << std::endl;std::cout << std::string("or ") + std::to_string(((flags) | (mask))) << std::endl;std::cout << std::string("xor ") + std::to_string(((flags) ^ (mask))) << std::endl;std::cout << std::string("not ") + std::to_string((~flags)) << std::endl;return 0;The complete file
#include <memory>#include <iostream>#include <string>
// define classes here to avoid compiler errorsclass Main;
// header definitionsclass Main { public : /* class constructor */ Main( ); /* static methods */ static void main();};
int __g_argc;char **__g_argv;Main::Main( ) {}int main(int argc, char* argv[]) { __g_argc = argc; __g_argv = argv; int flags = 12; int mask = 10; std::cout << std::string("and ") + std::to_string(((flags) & (mask))) << std::endl; std::cout << std::string("or ") + std::to_string(((flags) | (mask))) << std::endl; std::cout << std::string("xor ") + std::to_string(((flags) ^ (mask))) << std::endl; std::cout << std::string("not ") + std::to_string((~flags)) << std::endl; return 0;}$flags = 12;$mask = 10;echo( "and " . (($flags) & ($mask)) . "\n");echo( "or " . (($flags) | ($mask)) . "\n");echo( "xor " . (($flags) ^ ($mask)) . "\n");echo( "not " . (~$flags) . "\n");The complete file
<?php
class Main { function __construct( ) { }}/* static PHP main routine */$flags = 12;$mask = 10;echo( "and " . (($flags) & ($mask)) . "\n");echo( "or " . (($flags) | ($mask)) . "\n");echo( "xor " . (($flags) ^ ($mask)) . "\n");echo( "not " . (~$flags) . "\n");val flags : Int = 12val mask : Int = 10println( "and " + ((flags) & (mask)) )println( "or " + ((flags) | (mask)) )println( "xor " + ((flags) ^ (mask)) )println( "not " + (~flags) )The complete file
case class ScalaReturnValue(value:Any) extends Exception
// application main function for Mainobject AppMain extends App { val flags : Int = 12 val mask : Int = 10 println( "and " + ((flags) & (mask)) ) println( "or " + ((flags) | (mask)) ) println( "xor " + ((flags) ^ (mask)) ) println( "not " + (~flags) )}Definition: compiler/Lang.rgr, line 4628
bit_not
(bit_not value) → int
bit_not(value: int)Bitwise NOT (ones complement)
Target support
- JavaScript: own template
- TypeScript: own template
- Go: own template
- Rust: own template
- Python: own template
- Java: own template
- Kotlin: own template
- Dart: default template
- Swift: own template
- C#: own template
- C++: own template
- PHP: default template
- Scala: default template
Bit operations on an integer
class Main { sfn main:void () { def flags 12 def mask 10 print ("and " + (bit_and flags mask)) print ("or " + (bit_or flags mask)) print ("xor " + (bit_xor flags mask)) print ("not " + (bit_not flags)) }}const flags = 12;const mask = 10;console.log("and " + (flags & mask));console.log("or " + (flags | mask));console.log("xor " + (flags ^ mask));console.log("not " + (~flags));The complete file
class Main { constructor() { }}/* static JavaSript main routine at the end of the JS file */function __js_main() { const flags = 12; const mask = 10; console.log("and " + (flags & mask)); console.log("or " + (flags | mask)); console.log("xor " + (flags ^ mask)); console.log("not " + (~flags));}__js_main();const flags : number = 12;const mask : number = 10;console.log("and " + (flags & mask));console.log("or " + (flags | mask));console.log("xor " + (flags ^ mask));console.log("not " + (~flags));The complete file
export class Main { constructor() { }}/* static JavaSript main routine at the end of the JS file */function __js_main() { const flags : number = 12; const mask : number = 10; console.log("and " + (flags & mask)); console.log("or " + (flags | mask)); console.log("xor " + (flags ^ mask)); console.log("not " + (~flags));}__js_main();var flags int64= int64(12);var mask int64= int64(10);fmt.Println( strings.Join([]string{ "and ",strconv.FormatInt(int64(flags & mask), 10) }, "") )fmt.Println( strings.Join([]string{ "or ",strconv.FormatInt(int64(flags | mask), 10) }, "") )fmt.Println( strings.Join([]string{ "xor ",strconv.FormatInt(int64(flags ^ mask), 10) }, "") )fmt.Println( strings.Join([]string{ "not ",strconv.FormatInt(int64(^flags), 10) }, "") )The complete file
package mainimport ( "strings" "strconv" "fmt")type Main struct {}
func CreateNew_Main() *Main { me := new(Main) return me;}func main() { var flags int64= int64(12); var mask int64= int64(10); fmt.Println( strings.Join([]string{ "and ",strconv.FormatInt(int64(flags & mask), 10) }, "") ) fmt.Println( strings.Join([]string{ "or ",strconv.FormatInt(int64(flags | mask), 10) }, "") ) fmt.Println( strings.Join([]string{ "xor ",strconv.FormatInt(int64(flags ^ mask), 10) }, "") ) fmt.Println( strings.Join([]string{ "not ",strconv.FormatInt(int64(^flags), 10) }, "") )}let __rg_main_thread = std::thread::Builder::new().stack_size(512 * 1024 * 1024) .spawn(__rg_main_body).expect("could not start the main thread");__rg_main_thread.join().expect("main thread panicked");The complete file
#![allow(dead_code)]
#[derive(Clone)]struct Main {}impl Main { pub fn new() -> Self { Self { } }}fn main() { let __rg_main_thread = std::thread::Builder::new().stack_size(512 * 1024 * 1024) .spawn(__rg_main_body).expect("could not start the main thread"); __rg_main_thread.join().expect("main thread panicked");}fn __rg_main_body() { let flags: i64 = 12; let mask: i64 = 10; println!("and {}", flags & mask); println!("or {}", flags | mask); println!("xor {}", flags ^ mask); println!("not {}", (!flags));}flags = 12mask = 10print("and " + str(((flags) & (mask))))print("or " + str(((flags) | (mask))))print("xor " + str(((flags) ^ (mask))))print("not " + str((~flags)))The complete file
# -*- coding: utf-8 -*-from __future__ import annotationsfrom typing import Optional
class Main: def __init__(self) -> None: pass# Main entry pointdef main(): flags = 12 mask = 10 print("and " + str(((flags) & (mask)))) print("or " + str(((flags) | (mask)))) print("xor " + str(((flags) ^ (mask)))) print("not " + str((~flags)))if __name__ == "__main__": main()RgArgs.args = args;final Integer flags = 12;final Integer mask = 10;System.out.println(String.valueOf( "and " + ((flags) & (mask)) ) );System.out.println(String.valueOf( "or " + ((flags) | (mask)) ) );System.out.println(String.valueOf( "xor " + ((flags) ^ (mask)) ) );System.out.println(String.valueOf( "not " + (~flags) ) );The complete file
import java.io.*;
public class Main {
public static void main(String [] args ) { RgArgs.args = args; final Integer flags = 12; final Integer mask = 10; System.out.println(String.valueOf( "and " + ((flags) & (mask)) ) ); System.out.println(String.valueOf( "or " + ((flags) | (mask)) ) ); System.out.println(String.valueOf( "xor " + ((flags) ^ (mask)) ) ); System.out.println(String.valueOf( "not " + (~flags) ) ); }}
public class RgArgs { public static String[] args = new String[0];}__g_args = argsval flags : Int = 12;val mask : Int = 10;println( "and " + (((flags) and (mask))).toString() )println( "or " + (((flags) or (mask))).toString() )println( "xor " + (((flags) xor (mask))).toString() )println( "not " + (((flags).inv())).toString() )The complete file
class Main {
}
var __g_args : Array<String> = arrayOf()
fun main(args : Array<String>) { __g_args = args val flags : Int = 12; val mask : Int = 10; println( "and " + (((flags) and (mask))).toString() ) println( "or " + (((flags) or (mask))).toString() ) println( "xor " + (((flags) xor (mask))).toString() ) println( "not " + (((flags).inv())).toString() )}__g_args = args;int flags = 12;int mask = 10;print( "and " + (((flags) & (mask))).toString() );print( "or " + (((flags) | (mask))).toString() );print( "xor " + (((flags) ^ (mask))).toString() );print( "not " + ((~flags)).toString() );The complete file
class Main {}
List<String> __g_args = <String>[];
void main(List<String> args) { __g_args = args; int flags = 12; int mask = 10; print( "and " + (((flags) & (mask))).toString() ); print( "or " + (((flags) | (mask))).toString() ); print( "xor " + (((flags) ^ (mask))).toString() ); print( "not " + ((~flags)).toString() );}let flags : Int = 12let mask : Int = 10print("and " + String(((flags) & (mask))))print("or " + String(((flags) | (mask))))print("xor " + String(((flags) ^ (mask))))print("not " + String((~(flags))))The complete file
func ==(l: Main, r: Main) -> Bool { return l === r}final class Main : Hashable { func hash(into hasher: inout Hasher) { hasher.combine(ObjectIdentifier(self)) }}// Main entry pointfunc __main__swift() { let flags : Int = 12 let mask : Int = 10 print("and " + String(((flags) & (mask)))) print("or " + String(((flags) | (mask)))) print("xor " + String(((flags) ^ (mask)))) print("not " + String((~(flags))))}__main__swift()int flags = 12;int mask = 10;Console.WriteLine("and " + ((flags) & (mask)));Console.WriteLine("or " + ((flags) | (mask)));Console.WriteLine("xor " + ((flags) ^ (mask)));Console.WriteLine("not " + (~flags));The complete file
using System;class Main { static void Main( string [] args ) { int flags = 12; int mask = 10; Console.WriteLine("and " + ((flags) & (mask))); Console.WriteLine("or " + ((flags) | (mask))); Console.WriteLine("xor " + ((flags) ^ (mask))); Console.WriteLine("not " + (~flags)); }}int flags = 12;int mask = 10;std::cout << std::string("and ") + std::to_string(((flags) & (mask))) << std::endl;std::cout << std::string("or ") + std::to_string(((flags) | (mask))) << std::endl;std::cout << std::string("xor ") + std::to_string(((flags) ^ (mask))) << std::endl;std::cout << std::string("not ") + std::to_string((~flags)) << std::endl;return 0;The complete file
#include <memory>#include <iostream>#include <string>
// define classes here to avoid compiler errorsclass Main;
// header definitionsclass Main { public : /* class constructor */ Main( ); /* static methods */ static void main();};
int __g_argc;char **__g_argv;Main::Main( ) {}int main(int argc, char* argv[]) { __g_argc = argc; __g_argv = argv; int flags = 12; int mask = 10; std::cout << std::string("and ") + std::to_string(((flags) & (mask))) << std::endl; std::cout << std::string("or ") + std::to_string(((flags) | (mask))) << std::endl; std::cout << std::string("xor ") + std::to_string(((flags) ^ (mask))) << std::endl; std::cout << std::string("not ") + std::to_string((~flags)) << std::endl; return 0;}$flags = 12;$mask = 10;echo( "and " . (($flags) & ($mask)) . "\n");echo( "or " . (($flags) | ($mask)) . "\n");echo( "xor " . (($flags) ^ ($mask)) . "\n");echo( "not " . (~$flags) . "\n");The complete file
<?php
class Main { function __construct( ) { }}/* static PHP main routine */$flags = 12;$mask = 10;echo( "and " . (($flags) & ($mask)) . "\n");echo( "or " . (($flags) | ($mask)) . "\n");echo( "xor " . (($flags) ^ ($mask)) . "\n");echo( "not " . (~$flags) . "\n");val flags : Int = 12val mask : Int = 10println( "and " + ((flags) & (mask)) )println( "or " + ((flags) | (mask)) )println( "xor " + ((flags) ^ (mask)) )println( "not " + (~flags) )The complete file
case class ScalaReturnValue(value:Any) extends Exception
// application main function for Mainobject AppMain extends App { val flags : Int = 12 val mask : Int = 10 println( "and " + ((flags) & (mask)) ) println( "or " + ((flags) | (mask)) ) println( "xor " + ((flags) ^ (mask)) ) println( "not " + (~flags) )}Definition: compiler/Lang.rgr, line 4678
bit_or
(bit_or left right) → int
bit_or(left: int, right: int)Bitwise OR
Target support
- JavaScript: own template
- TypeScript: own template
- Go: own template
- Rust: own template
- Python: own template
- Java: own template
- Kotlin: own template
- Dart: default template
- Swift: own template
- C#: own template
- C++: own template
- PHP: default template
- Scala: default template
Bit operations on an integer
class Main { sfn main:void () { def flags 12 def mask 10 print ("and " + (bit_and flags mask)) print ("or " + (bit_or flags mask)) print ("xor " + (bit_xor flags mask)) print ("not " + (bit_not flags)) }}const flags = 12;const mask = 10;console.log("and " + (flags & mask));console.log("or " + (flags | mask));console.log("xor " + (flags ^ mask));console.log("not " + (~flags));The complete file
class Main { constructor() { }}/* static JavaSript main routine at the end of the JS file */function __js_main() { const flags = 12; const mask = 10; console.log("and " + (flags & mask)); console.log("or " + (flags | mask)); console.log("xor " + (flags ^ mask)); console.log("not " + (~flags));}__js_main();const flags : number = 12;const mask : number = 10;console.log("and " + (flags & mask));console.log("or " + (flags | mask));console.log("xor " + (flags ^ mask));console.log("not " + (~flags));The complete file
export class Main { constructor() { }}/* static JavaSript main routine at the end of the JS file */function __js_main() { const flags : number = 12; const mask : number = 10; console.log("and " + (flags & mask)); console.log("or " + (flags | mask)); console.log("xor " + (flags ^ mask)); console.log("not " + (~flags));}__js_main();var flags int64= int64(12);var mask int64= int64(10);fmt.Println( strings.Join([]string{ "and ",strconv.FormatInt(int64(flags & mask), 10) }, "") )fmt.Println( strings.Join([]string{ "or ",strconv.FormatInt(int64(flags | mask), 10) }, "") )fmt.Println( strings.Join([]string{ "xor ",strconv.FormatInt(int64(flags ^ mask), 10) }, "") )fmt.Println( strings.Join([]string{ "not ",strconv.FormatInt(int64(^flags), 10) }, "") )The complete file
package mainimport ( "strings" "strconv" "fmt")type Main struct {}
func CreateNew_Main() *Main { me := new(Main) return me;}func main() { var flags int64= int64(12); var mask int64= int64(10); fmt.Println( strings.Join([]string{ "and ",strconv.FormatInt(int64(flags & mask), 10) }, "") ) fmt.Println( strings.Join([]string{ "or ",strconv.FormatInt(int64(flags | mask), 10) }, "") ) fmt.Println( strings.Join([]string{ "xor ",strconv.FormatInt(int64(flags ^ mask), 10) }, "") ) fmt.Println( strings.Join([]string{ "not ",strconv.FormatInt(int64(^flags), 10) }, "") )}let __rg_main_thread = std::thread::Builder::new().stack_size(512 * 1024 * 1024) .spawn(__rg_main_body).expect("could not start the main thread");__rg_main_thread.join().expect("main thread panicked");The complete file
#![allow(dead_code)]
#[derive(Clone)]struct Main {}impl Main { pub fn new() -> Self { Self { } }}fn main() { let __rg_main_thread = std::thread::Builder::new().stack_size(512 * 1024 * 1024) .spawn(__rg_main_body).expect("could not start the main thread"); __rg_main_thread.join().expect("main thread panicked");}fn __rg_main_body() { let flags: i64 = 12; let mask: i64 = 10; println!("and {}", flags & mask); println!("or {}", flags | mask); println!("xor {}", flags ^ mask); println!("not {}", (!flags));}flags = 12mask = 10print("and " + str(((flags) & (mask))))print("or " + str(((flags) | (mask))))print("xor " + str(((flags) ^ (mask))))print("not " + str((~flags)))The complete file
# -*- coding: utf-8 -*-from __future__ import annotationsfrom typing import Optional
class Main: def __init__(self) -> None: pass# Main entry pointdef main(): flags = 12 mask = 10 print("and " + str(((flags) & (mask)))) print("or " + str(((flags) | (mask)))) print("xor " + str(((flags) ^ (mask)))) print("not " + str((~flags)))if __name__ == "__main__": main()RgArgs.args = args;final Integer flags = 12;final Integer mask = 10;System.out.println(String.valueOf( "and " + ((flags) & (mask)) ) );System.out.println(String.valueOf( "or " + ((flags) | (mask)) ) );System.out.println(String.valueOf( "xor " + ((flags) ^ (mask)) ) );System.out.println(String.valueOf( "not " + (~flags) ) );The complete file
import java.io.*;
public class Main {
public static void main(String [] args ) { RgArgs.args = args; final Integer flags = 12; final Integer mask = 10; System.out.println(String.valueOf( "and " + ((flags) & (mask)) ) ); System.out.println(String.valueOf( "or " + ((flags) | (mask)) ) ); System.out.println(String.valueOf( "xor " + ((flags) ^ (mask)) ) ); System.out.println(String.valueOf( "not " + (~flags) ) ); }}
public class RgArgs { public static String[] args = new String[0];}__g_args = argsval flags : Int = 12;val mask : Int = 10;println( "and " + (((flags) and (mask))).toString() )println( "or " + (((flags) or (mask))).toString() )println( "xor " + (((flags) xor (mask))).toString() )println( "not " + (((flags).inv())).toString() )The complete file
class Main {
}
var __g_args : Array<String> = arrayOf()
fun main(args : Array<String>) { __g_args = args val flags : Int = 12; val mask : Int = 10; println( "and " + (((flags) and (mask))).toString() ) println( "or " + (((flags) or (mask))).toString() ) println( "xor " + (((flags) xor (mask))).toString() ) println( "not " + (((flags).inv())).toString() )}__g_args = args;int flags = 12;int mask = 10;print( "and " + (((flags) & (mask))).toString() );print( "or " + (((flags) | (mask))).toString() );print( "xor " + (((flags) ^ (mask))).toString() );print( "not " + ((~flags)).toString() );The complete file
class Main {}
List<String> __g_args = <String>[];
void main(List<String> args) { __g_args = args; int flags = 12; int mask = 10; print( "and " + (((flags) & (mask))).toString() ); print( "or " + (((flags) | (mask))).toString() ); print( "xor " + (((flags) ^ (mask))).toString() ); print( "not " + ((~flags)).toString() );}let flags : Int = 12let mask : Int = 10print("and " + String(((flags) & (mask))))print("or " + String(((flags) | (mask))))print("xor " + String(((flags) ^ (mask))))print("not " + String((~(flags))))The complete file
func ==(l: Main, r: Main) -> Bool { return l === r}final class Main : Hashable { func hash(into hasher: inout Hasher) { hasher.combine(ObjectIdentifier(self)) }}// Main entry pointfunc __main__swift() { let flags : Int = 12 let mask : Int = 10 print("and " + String(((flags) & (mask)))) print("or " + String(((flags) | (mask)))) print("xor " + String(((flags) ^ (mask)))) print("not " + String((~(flags))))}__main__swift()int flags = 12;int mask = 10;Console.WriteLine("and " + ((flags) & (mask)));Console.WriteLine("or " + ((flags) | (mask)));Console.WriteLine("xor " + ((flags) ^ (mask)));Console.WriteLine("not " + (~flags));The complete file
using System;class Main { static void Main( string [] args ) { int flags = 12; int mask = 10; Console.WriteLine("and " + ((flags) & (mask))); Console.WriteLine("or " + ((flags) | (mask))); Console.WriteLine("xor " + ((flags) ^ (mask))); Console.WriteLine("not " + (~flags)); }}int flags = 12;int mask = 10;std::cout << std::string("and ") + std::to_string(((flags) & (mask))) << std::endl;std::cout << std::string("or ") + std::to_string(((flags) | (mask))) << std::endl;std::cout << std::string("xor ") + std::to_string(((flags) ^ (mask))) << std::endl;std::cout << std::string("not ") + std::to_string((~flags)) << std::endl;return 0;The complete file
#include <memory>#include <iostream>#include <string>
// define classes here to avoid compiler errorsclass Main;
// header definitionsclass Main { public : /* class constructor */ Main( ); /* static methods */ static void main();};
int __g_argc;char **__g_argv;Main::Main( ) {}int main(int argc, char* argv[]) { __g_argc = argc; __g_argv = argv; int flags = 12; int mask = 10; std::cout << std::string("and ") + std::to_string(((flags) & (mask))) << std::endl; std::cout << std::string("or ") + std::to_string(((flags) | (mask))) << std::endl; std::cout << std::string("xor ") + std::to_string(((flags) ^ (mask))) << std::endl; std::cout << std::string("not ") + std::to_string((~flags)) << std::endl; return 0;}$flags = 12;$mask = 10;echo( "and " . (($flags) & ($mask)) . "\n");echo( "or " . (($flags) | ($mask)) . "\n");echo( "xor " . (($flags) ^ ($mask)) . "\n");echo( "not " . (~$flags) . "\n");The complete file
<?php
class Main { function __construct( ) { }}/* static PHP main routine */$flags = 12;$mask = 10;echo( "and " . (($flags) & ($mask)) . "\n");echo( "or " . (($flags) | ($mask)) . "\n");echo( "xor " . (($flags) ^ ($mask)) . "\n");echo( "not " . (~$flags) . "\n");val flags : Int = 12val mask : Int = 10println( "and " + ((flags) & (mask)) )println( "or " + ((flags) | (mask)) )println( "xor " + ((flags) ^ (mask)) )println( "not " + (~flags) )The complete file
case class ScalaReturnValue(value:Any) extends Exception
// application main function for Mainobject AppMain extends App { val flags : Int = 12 val mask : Int = 10 println( "and " + ((flags) & (mask)) ) println( "or " + ((flags) | (mask)) ) println( "xor " + ((flags) ^ (mask)) ) println( "not " + (~flags) )}Definition: compiler/Lang.rgr, line 4646
bit_xor
(bit_xor left right) → int
bit_xor(left: int, right: int)Bitwise XOR
Target support
- JavaScript: own template
- TypeScript: own template
- Go: own template
- Rust: own template
- Python: own template
- Java: own template
- Kotlin: own template
- Dart: default template
- Swift: own template
- C#: own template
- C++: own template
- PHP: default template
- Scala: default template
Bit operations on an integer
class Main { sfn main:void () { def flags 12 def mask 10 print ("and " + (bit_and flags mask)) print ("or " + (bit_or flags mask)) print ("xor " + (bit_xor flags mask)) print ("not " + (bit_not flags)) }}const flags = 12;const mask = 10;console.log("and " + (flags & mask));console.log("or " + (flags | mask));console.log("xor " + (flags ^ mask));console.log("not " + (~flags));The complete file
class Main { constructor() { }}/* static JavaSript main routine at the end of the JS file */function __js_main() { const flags = 12; const mask = 10; console.log("and " + (flags & mask)); console.log("or " + (flags | mask)); console.log("xor " + (flags ^ mask)); console.log("not " + (~flags));}__js_main();const flags : number = 12;const mask : number = 10;console.log("and " + (flags & mask));console.log("or " + (flags | mask));console.log("xor " + (flags ^ mask));console.log("not " + (~flags));The complete file
export class Main { constructor() { }}/* static JavaSript main routine at the end of the JS file */function __js_main() { const flags : number = 12; const mask : number = 10; console.log("and " + (flags & mask)); console.log("or " + (flags | mask)); console.log("xor " + (flags ^ mask)); console.log("not " + (~flags));}__js_main();var flags int64= int64(12);var mask int64= int64(10);fmt.Println( strings.Join([]string{ "and ",strconv.FormatInt(int64(flags & mask), 10) }, "") )fmt.Println( strings.Join([]string{ "or ",strconv.FormatInt(int64(flags | mask), 10) }, "") )fmt.Println( strings.Join([]string{ "xor ",strconv.FormatInt(int64(flags ^ mask), 10) }, "") )fmt.Println( strings.Join([]string{ "not ",strconv.FormatInt(int64(^flags), 10) }, "") )The complete file
package mainimport ( "strings" "strconv" "fmt")type Main struct {}
func CreateNew_Main() *Main { me := new(Main) return me;}func main() { var flags int64= int64(12); var mask int64= int64(10); fmt.Println( strings.Join([]string{ "and ",strconv.FormatInt(int64(flags & mask), 10) }, "") ) fmt.Println( strings.Join([]string{ "or ",strconv.FormatInt(int64(flags | mask), 10) }, "") ) fmt.Println( strings.Join([]string{ "xor ",strconv.FormatInt(int64(flags ^ mask), 10) }, "") ) fmt.Println( strings.Join([]string{ "not ",strconv.FormatInt(int64(^flags), 10) }, "") )}let __rg_main_thread = std::thread::Builder::new().stack_size(512 * 1024 * 1024) .spawn(__rg_main_body).expect("could not start the main thread");__rg_main_thread.join().expect("main thread panicked");The complete file
#![allow(dead_code)]
#[derive(Clone)]struct Main {}impl Main { pub fn new() -> Self { Self { } }}fn main() { let __rg_main_thread = std::thread::Builder::new().stack_size(512 * 1024 * 1024) .spawn(__rg_main_body).expect("could not start the main thread"); __rg_main_thread.join().expect("main thread panicked");}fn __rg_main_body() { let flags: i64 = 12; let mask: i64 = 10; println!("and {}", flags & mask); println!("or {}", flags | mask); println!("xor {}", flags ^ mask); println!("not {}", (!flags));}flags = 12mask = 10print("and " + str(((flags) & (mask))))print("or " + str(((flags) | (mask))))print("xor " + str(((flags) ^ (mask))))print("not " + str((~flags)))The complete file
# -*- coding: utf-8 -*-from __future__ import annotationsfrom typing import Optional
class Main: def __init__(self) -> None: pass# Main entry pointdef main(): flags = 12 mask = 10 print("and " + str(((flags) & (mask)))) print("or " + str(((flags) | (mask)))) print("xor " + str(((flags) ^ (mask)))) print("not " + str((~flags)))if __name__ == "__main__": main()RgArgs.args = args;final Integer flags = 12;final Integer mask = 10;System.out.println(String.valueOf( "and " + ((flags) & (mask)) ) );System.out.println(String.valueOf( "or " + ((flags) | (mask)) ) );System.out.println(String.valueOf( "xor " + ((flags) ^ (mask)) ) );System.out.println(String.valueOf( "not " + (~flags) ) );The complete file
import java.io.*;
public class Main {
public static void main(String [] args ) { RgArgs.args = args; final Integer flags = 12; final Integer mask = 10; System.out.println(String.valueOf( "and " + ((flags) & (mask)) ) ); System.out.println(String.valueOf( "or " + ((flags) | (mask)) ) ); System.out.println(String.valueOf( "xor " + ((flags) ^ (mask)) ) ); System.out.println(String.valueOf( "not " + (~flags) ) ); }}
public class RgArgs { public static String[] args = new String[0];}__g_args = argsval flags : Int = 12;val mask : Int = 10;println( "and " + (((flags) and (mask))).toString() )println( "or " + (((flags) or (mask))).toString() )println( "xor " + (((flags) xor (mask))).toString() )println( "not " + (((flags).inv())).toString() )The complete file
class Main {
}
var __g_args : Array<String> = arrayOf()
fun main(args : Array<String>) { __g_args = args val flags : Int = 12; val mask : Int = 10; println( "and " + (((flags) and (mask))).toString() ) println( "or " + (((flags) or (mask))).toString() ) println( "xor " + (((flags) xor (mask))).toString() ) println( "not " + (((flags).inv())).toString() )}__g_args = args;int flags = 12;int mask = 10;print( "and " + (((flags) & (mask))).toString() );print( "or " + (((flags) | (mask))).toString() );print( "xor " + (((flags) ^ (mask))).toString() );print( "not " + ((~flags)).toString() );The complete file
class Main {}
List<String> __g_args = <String>[];
void main(List<String> args) { __g_args = args; int flags = 12; int mask = 10; print( "and " + (((flags) & (mask))).toString() ); print( "or " + (((flags) | (mask))).toString() ); print( "xor " + (((flags) ^ (mask))).toString() ); print( "not " + ((~flags)).toString() );}let flags : Int = 12let mask : Int = 10print("and " + String(((flags) & (mask))))print("or " + String(((flags) | (mask))))print("xor " + String(((flags) ^ (mask))))print("not " + String((~(flags))))The complete file
func ==(l: Main, r: Main) -> Bool { return l === r}final class Main : Hashable { func hash(into hasher: inout Hasher) { hasher.combine(ObjectIdentifier(self)) }}// Main entry pointfunc __main__swift() { let flags : Int = 12 let mask : Int = 10 print("and " + String(((flags) & (mask)))) print("or " + String(((flags) | (mask)))) print("xor " + String(((flags) ^ (mask)))) print("not " + String((~(flags))))}__main__swift()int flags = 12;int mask = 10;Console.WriteLine("and " + ((flags) & (mask)));Console.WriteLine("or " + ((flags) | (mask)));Console.WriteLine("xor " + ((flags) ^ (mask)));Console.WriteLine("not " + (~flags));The complete file
using System;class Main { static void Main( string [] args ) { int flags = 12; int mask = 10; Console.WriteLine("and " + ((flags) & (mask))); Console.WriteLine("or " + ((flags) | (mask))); Console.WriteLine("xor " + ((flags) ^ (mask))); Console.WriteLine("not " + (~flags)); }}int flags = 12;int mask = 10;std::cout << std::string("and ") + std::to_string(((flags) & (mask))) << std::endl;std::cout << std::string("or ") + std::to_string(((flags) | (mask))) << std::endl;std::cout << std::string("xor ") + std::to_string(((flags) ^ (mask))) << std::endl;std::cout << std::string("not ") + std::to_string((~flags)) << std::endl;return 0;The complete file
#include <memory>#include <iostream>#include <string>
// define classes here to avoid compiler errorsclass Main;
// header definitionsclass Main { public : /* class constructor */ Main( ); /* static methods */ static void main();};
int __g_argc;char **__g_argv;Main::Main( ) {}int main(int argc, char* argv[]) { __g_argc = argc; __g_argv = argv; int flags = 12; int mask = 10; std::cout << std::string("and ") + std::to_string(((flags) & (mask))) << std::endl; std::cout << std::string("or ") + std::to_string(((flags) | (mask))) << std::endl; std::cout << std::string("xor ") + std::to_string(((flags) ^ (mask))) << std::endl; std::cout << std::string("not ") + std::to_string((~flags)) << std::endl; return 0;}$flags = 12;$mask = 10;echo( "and " . (($flags) & ($mask)) . "\n");echo( "or " . (($flags) | ($mask)) . "\n");echo( "xor " . (($flags) ^ ($mask)) . "\n");echo( "not " . (~$flags) . "\n");The complete file
<?php
class Main { function __construct( ) { }}/* static PHP main routine */$flags = 12;$mask = 10;echo( "and " . (($flags) & ($mask)) . "\n");echo( "or " . (($flags) | ($mask)) . "\n");echo( "xor " . (($flags) ^ ($mask)) . "\n");echo( "not " . (~$flags) . "\n");val flags : Int = 12val mask : Int = 10println( "and " + ((flags) & (mask)) )println( "or " + ((flags) | (mask)) )println( "xor " + ((flags) ^ (mask)) )println( "not " + (~flags) )The complete file
case class ScalaReturnValue(value:Any) extends Exception
// application main function for Mainobject AppMain extends App { val flags : Int = 12 val mask : Int = 10 println( "and " + ((flags) & (mask)) ) println( "or " + ((flags) | (mask)) ) println( "xor " + ((flags) ^ (mask)) ) println( "not " + (~flags) )}Definition: compiler/Lang.rgr, line 4662
Ranger 3.5.1 · commit f323fd4 · development build