What is a single pipe equivalent in dart?

62
May 12, 2022, at 10:50 PM

I'm attempting to convert a piece of PHP code to dart and I came across a few things I've simply never used before, one of which is a single pipe |. Im not sure what the exact dart equivalent is, if there even is one.

The piece of code in PHP I'm attempting to convert is:

$cc1 = (chr(ord($c1) / 64) | "\xc0");

What I've got so far converted into dart is:

var cc1 = (String.fromCharCode(c1.codeUnitAt(0) / 64) | "\xc0");

However, the single pipe | is giving me a dart error The operator '|' isn't defined for the type 'String'., but as far as I can tell, the php chr should be giving a string as its output, so it brings up the question of if single pipe is actually doing the same thing in dart as it does in PHP?

Answer 1

The operation is bitwise-OR, and the equivalent operator is |. However, PHP is lenient about types, and Dart is type-safe. It will not convert strings to integers for you. You can do:

var cc1 = c1.codeUnitAt(0) | 0xc0;

cc1 will be an int. If, say, you want it to be a String with the hexadecimal representation, you can do:

var cc1 = (c1.codeUnitAt(0) | 0xc0).toRadixString(16);
READ ALSO
What is the proper way to do a foreach loop with an Array/Map in dart?

What is the proper way to do a foreach loop with an Array/Map in dart?

I'm trying to convert a piece of PHP code to dart and getting stuckWhat I have is a PHP array text that gets run through a function called toUTF8 as follows:

64
Laravel Error: Details blade displays wrong data, displays previous column data

Laravel Error: Details blade displays wrong data, displays previous column data

I have a Details page that displays "short description", "Duration", and "description of tour" from a database

28
File Download via API using Guzzle

File Download via API using Guzzle

I'm still on the learning slopes with Guzzle, but am stumped with this issue

39
How would i curl a hls using php

How would i curl a hls using php

I want to curl a HLS that returns forbidden in the browser with Php so in another words i want to return the contents of say

73