0
In an attempt to create a column with binary 32-bit numbers
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('teams', function (Blueprint $table) {
$table->increments('id');
$table->char('binary_number', 32)->charset('binary'); // Em: https://stackoverflow.com/a/62615777/5675325
$table->timestamps();
});
}
Of note
$table->char('binary_number', 32)->charset('binary');
When I see the same through Heidisql I can see that you’re the type BINARY
size 32.
When creating the seeder to popular with the desired data, I tried
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('teams')->insert([
'id' => 1,
'binary_number' => 2,
'created_at' => now(),
'updated_at' => now()
]);
Turns out if I use 2 or 101 on binary_number
, will result in DB value 2 or 101, respectively.
How much I experience 00000000000000000000000000000010
(equivalent to 2 in 32-bit binary) and 00000000000000000000000001100101
(which equals 101 in 32-bit binary)
'binary_number' => 00000000000000000000000000000010,
then I get the value 8 and 294977 respectively.
However, what I seek is that 2 be kept as 00000000000000000000000000000010
and the 101 as 00000000000000000000000001100101
.
294977 (decimal) = 1100101 (octal) and 8 (top) = 10 (octal)
– Augusto Vasques
@Augustovasques and if I want 2 to be stored as
0000000000000000000000000000000000000010
?– Tiago Martins Peres 李大仁
It’s not the storage you have to worry about is the formatting while displaying the data. I am without the link I think the PHP documentation server is under maintenance but has the functions
decoct()
andbase_convert()
to the auxiliary.– Augusto Vasques